The FizzBuzz Function
Part of the Fundamentals section of Coddy's Python journey — lesson 50 of 77.
Challenge
EasyAdd a function named fizzbuzz that gets one number (int) as an argument, and:
- If the number is divisible by 3, return
"Fizz". - If the number is divisible by 7, return
"Buzz". - If the number is divisible by both 3 and 7, return
"FizzBuzz". - If none of the above conditions are met, return the number itself in a string format.
After the function:
- Get input and cast it to int
- Call the function
fizzbuzzwith the input number - Print the output of the function
Try it yourself
print("Welcome to FizzBuzz!")
def fizzbuzz(number):
# Write your code here
limit = int(input())
# Print the output of the functionAll lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 48Loops
For LoopWhile LoopBreakContinueRecap - FactorialThe Range FunctionNested LoopRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators9Functions
Declare a FunctionArgumentsReturnRecap - Sigma FunctionRecap - Validation FunctionDefault Values12Iterating Over Sequences
Iterating Over ElementsThe Enumerate FunctionIterating Over Strings Part 1Iterating Over Strings Part 2