-
Notifications
You must be signed in to change notification settings - Fork 0
/
guessingGame.py
64 lines (46 loc) · 1.57 KB
/
guessingGame.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
import random
random_number = random.randint(1, 10) # numbers 1 -10
'''
user_guess = input('Guess the number: ')
## handle user guesses
# first attempt, was stuck on working the while loop in
if int(user_guess) == random_number:
print('Correct!') # if they guess correct, tell them they win
elif int(user_guess) > random_number:
print('Wrong, try a lower number')
else:
print('Wrong, try a higher number')
#otherwise tell them they are too high or too low
print(random_number)
'''
#BONUS - let player play again if they want
#using solution as help to work forwards
'''
user_guess = ''
while user_guess != random_number:
user_guess = input('Guess the number between 1 to 10: ')
if int(user_guess) < random_number:
print('Try a lower number')
elif int(user_guess) > random_number:
print('Try a higher number')
else:
print('You won')
print(random_number)
'''
#this version asks if the player wants to play agauser_guess = ''
while True:
user_guess = input('Guess the number between 1 to 10: ')
if int(user_guess) > random_number:
print('Try a lower number')
elif int(user_guess) < random_number:
print('Try a higher number')
else:
print('You won')
play_again = input('Do you want to play again? (y/n)')
if play_again == 'y':
random_number = random.randint(1, 10)
giess = None
else:
print('Thanks for playing!')
break
print(random_number)