-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber_game.py
More file actions
39 lines (32 loc) · 1.08 KB
/
number_game.py
File metadata and controls
39 lines (32 loc) · 1.08 KB
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
import random
# Generare a randome number between 1 and 10
secret_num = random.randint(1, 10)
def number_game():
i = 0
while i < 3:
guess = input("Guess a number between 1 and 10: ")
i += 1
if guess.isdigit():
guess = int(guess)
if guess == secret_num:
print("You got it! My number was {}.".format(secret_num))
try_again()
if i <= 2:
if guess > secret_num:
print("That's too high! You have used {} out of 3 guesses!".format(i))
else:
print("That's too low! You have used {} out of 3 guesses!".format(i))
if i > 2:
print("You have run out of guesses!")
try_again()
else:
print("Please enter a number!")
number_game()
def try_again():
again = input("Would you like to play again?\n")
again = again.upper()
if again == "YES":
number_game()
else:
quit()
number_game()