-
-
Save imranrbx/1a6ba9779c791e0d5c0e27fae4781f1b to your computer and use it in GitHub Desktop.
Guess the number game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
win = 0 | |
tries =0 | |
count = 3 | |
print ("Let's Play 'GUESS THE NUMBER' Game!") | |
ans = input("Are you ready to play? [yes/no] ") | |
while ans.lower() != "no": | |
print("I'm thinking number from 1 to 10, Guess It in 3 tries ") | |
guess = random.randint(1,10) | |
for count in range (3,0,-1): | |
print(str(count) + " Tries Left " if count > 0 else " No try left ") | |
try: | |
num = input("Do You Know what number I'm thinking? ") | |
if int(num)==guess: | |
print("You WON, I was also thinking same number" + str(guess)) | |
win+=1 | |
break | |
elif int(num)<guess: | |
print("Number you entered was less than what I was thinking" ) | |
else: | |
print("Number you entered was higher than what I was thinking" ) | |
except TypeError as err: | |
print(err) | |
except NameError as err: | |
print(err) | |
except ValueError as err: | |
print(err) | |
tries += 1 | |
ans=input("Play Again ? [yes/no]") | |
print("you played " + str(tries) + " Time%s" % ('s' if tries>1 else '')) | |
print("you won " + str(win) + " Time%s" % ('s' if tries>1 else '')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment