-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (43 loc) · 1.74 KB
/
main.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
import random
while True:
# Computer chooses a number between 0 and 10
computerNumber = random.randint(0,10)
# Checks if the number the player entered is an integer
while True:
try:
chances = int(input('How many chances would you like to have? Please enter an integer: '))
break
except ValueError:
print('\nPlease input a valid number.\n')
# Allows the player to choose a number and then checks if it is equal to the computer's number
while chances != 0:
# Checks if the player's number is an integer
while True:
try:
playerNumber = int(input('Guess a number: '))
break
except ValueError:
print('\nPlease input a valid number.\n')
if playerNumber == computerNumber:
print('\nCorrect!\n')
break
elif playerNumber < computerNumber:
print('\nIncorrect number. The number you chose is lower than the number the computer chose.\n')
chances = chances - 1
elif playerNumber > computerNumber:
print('\nIncorrect number. The number you chose is higher than the number the computer chose.\n')
chances = chances - 1
if chances == 0:
print('You have failed to guess the computer\'s number. The computer\'s number was ' + str(computerNumber) + '.\n')
while True:
playAgain = str.lower(input('Would you like to play again? (Y/n): '))
if playAgain == 'y':
print()
break
elif playAgain == 'n':
print('Thanks for playing!')
print('Terminating program...')
quit()
else:
print('Incorrect input.')
continue