-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizz_buzz_w_player.py
35 lines (31 loc) · 1002 Bytes
/
fizz_buzz_w_player.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
def fizz_buzz_w_player(number: int) -> str:
"""
Play Fizz buzz
:param number: The number to check.
:return: 'fizz' if the number is divisible by 3.
'buzz' if it's divisible by 5.
'fizz buzz' if it's divisible by both 3 and 5.
The number, as a string, otherwise.
"""
if number % 15 == 0:
return "fizz buzz"
elif number % 3 == 0:
return "fizz"
elif number % 5 == 0:
return "buzz"
else:
return str(number)
input("Play Fizz Buzz. Press ENTER to start")
print()
next_number = 0
while next_number < 99:
next_number += 1
print(fizz_buzz_w_player(next_number))
next_number += 1
correct_answer = fizz_buzz_w_player(next_number)
players_answer = input("Your go: ")
if players_answer != correct_answer:
print("You lose, the correct answer was {}".format(correct_answer))
break
else:
print("Well done, you reached {}".format(next_number))