Skip to content

Instantly share code, notes, and snippets.

@hahalim
Last active December 27, 2018 16:47
Show Gist options
  • Save hahalim/6a1827cd7b6c02e077d089499c174f97 to your computer and use it in GitHub Desktop.
Save hahalim/6a1827cd7b6c02e077d089499c174f97 to your computer and use it in GitHub Desktop.
Guess the number game
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 = int(input("Do You Know what number I'm thinking? "))
if num==guess:
print("You WON, I was also thinking same number" + str(guess))
win+=1
break
elif 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 ''))
@imranrbx
Copy link

Good Going try using (int) beside the input so that you don't need to type again again that (int)

@hahalim
Copy link
Author

hahalim commented Dec 27, 2018

Sir thanks for the feedback. I have made the required modifications.

@imranrbx
Copy link

Good Going, Keep it up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment