-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessTheNumber.py
More file actions
35 lines (28 loc) · 1.11 KB
/
GuessTheNumber.py
File metadata and controls
35 lines (28 loc) · 1.11 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
#Author: Emil
#Description: Guess the random number the computer generated
import random
while True:
print("Guess the number from 1-100, you have 7 tries!")
tries=1 # number of attempts user tried
guess=0 # the guess user tried
number = random.randint(1,100) # creates the randomly generated number
while tries < 7: #after 7 tries, user lost the game
guess=int(input("Try " + str(tries) + ": "))
tries+=1
if guess < number:
print("Too low!")
elif guess > number:
print("Too high!")
else:
break
if guess == number: #if user successfully guesses the number
print("You got it! Only took you " + str(tries-1) +" tries!")
else:
print("Shucks, you didn't get it, the number was "+ str(number))
reset = input("Do you want to try again? (Y/N)").lower() #to ask user if they want to repeat the game
if reset == 'y':
print("==================") # to distinguish between rounds
continue
else: # anything else other than a 'y' is going to end the game
print("Bye-Bye!")
break