-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizzbuzz.py
69 lines (62 loc) · 2.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def fizzbuzz():
while 1:
try:
first_num = input("This will make up your fizz. What number would you like to replace?")
first_num = int(first_num)
except ValueError:
print("User string is not a number.")
continue
print("Your first number is", first_num)
break
while 1:
try:
second_num = input("This will make up your buzz. What number would you like to replace?")
second_num = int(second_num)
except ValueError:
print("User string is not a number.")
continue
print("Your second number is", second_num)
break
while 1:
try:
user_min_range = input("What is the minimum number in your range?")
user_min_range = int(user_min_range)
except ValueError:
print("User string is not a number.")
continue
print("Your minimum number is", user_min_range)
break
while 1:
try:
user_max_range = input("What is the maximum number in your range?")
user_max_range = int(user_max_range)
except ValueError:
print("User string is not a number.")
continue
print("Your maximum number is", user_max_range)
break
for i in range(user_min_range, user_max_range):
if i % first_num == 0 and i % second_num == 0:
print("fizzbuzz")
elif i % first_num == 0:
print("fizz")
elif i % second_num == 0:
print("buzz")
else:
print(i)
while 1:
try:
answer = input("Would you like to try again? 1 = yes, 0 = no")
answer = int(answer)
except ValueError:
print("User string is not a number.")
continue
if answer != 1 and answer != 0:
print("That's not a valid response. Please select between 0 and 1.")
elif answer == 0:
print("Thanks for playing!")
break
else:
fizzbuzz()
break
fizzbuzz()