Advertisement
Blessing988

Untitled

Feb 22nd, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. def fizzbuzz(number): # the function should contain only one parameter
  2.  
  3. for num in range(1, (number + 1)): # signifies numbers from 1 to the number given
  4.  
  5. if num%3==0 and num%5==0: # number divisible by both 3 and 5
  6. print("FizzBuzz") # prints "FizzBuzz" if number is divsible by both 3 and 5
  7.  
  8. elif num%5==0: # number divisible by only 5
  9. print("Buzz") # prints "Buzz" if number is divisible by only 5
  10.  
  11. elif num%3==0: # number divisible by only 3
  12. print("Fizz") # prints "Fizz" if number is divisible by only 3
  13.  
  14. else:
  15. print(num) # prints the number if number is neither divisible by 3 nor 5
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. fizzbuzz(30) # Example the argument must be a positive whole number
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement