Write a simple function called fizzBuzz that takes in a positive integer, and returns ‘fizz’, ‘buzz’, ‘fizzbuzz’ or the argument it receives, based on the following:
Returns ‘fizz’ if the argument is divisible by 3
Returns buzz if the argument is divisible by 5
Returns ‘fizzBuzz’ if the argument is divisible by 3 and 5
Returns the argument itself if it is NOT divisible by 3 or 5
Returns exactly 'Invalid Argument' when an invalid argument is passed.
Examples:
Input Output
3 "fizz"
5 "buzz"
15 "fizzBuzz"
i tried out this code but it didnt work
def fizz_buzz(n):
n = []
for nums in n:
if nums % 5 == 0 and nums % 3 == 0:
print("fizz buzz")
elif nums % 3 == 0:
print("fizz")
elif nums % 5 == 0:
print("buzz")
elif nums % 3 != 0 and nums % 5 != 0:
print(nums)
else:
print("invalid argument")