-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfizzbuzz.py
29 lines (23 loc) · 1.07 KB
/
fizzbuzz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
Write a program that prints the numbers from 1 to 100.
But for multiples of three print “Fizz” instead of the number
For multiples of five print “Buzz”.
For numbers which are multiples of both three and five print “FizzBuzz”."
NOTE -> Must be in class and method format
"""
class Fizzy:
def fizzbuzz():
try:
n = int(input("Please select a number between 1 and 100: \n"))
except ValueError:
n = int(input("The input was not a valid integer or out of range. Please select a number between 1 and 100: \n"))
if n % 3 == 0 and n % 5 == 0:
return f"The number you have selected is: {n}\nThe outcome is: fizzbuzz"
elif n % 3 == 0:
return f"The number you have selected is: {n}\nThe outcome is: fizz"
elif n % 5 == 0:
return f"The number you have selected is: {n}\nThe outcome is: buzz"
else:
return f"The number you have selected is: {n}\nIt is neither divisible by 3 nor 5"
print(fizzbuzz())
Fizzy()