Created
December 20, 2018 18:15
-
-
Save imranrbx/c4e32fc29deea835005edf547ca82942 to your computer and use it in GitHub Desktop.
This is a simple logical game, where computer thinks about a number from 1 to 10 and you have to guess the number in 3 tries.
This file contains hidden or 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 = 0 | |
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 a Number from 1 to 10, Guess It In 3 Tries") | |
guess = random.randint(1, 10) | |
for count in range(3, 0, -1): | |
print(f"{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(f"You Won, I was also Thinking Same Number {guess}") | |
win += 1 | |
break | |
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(f"You Played {tries} Time%s" % ('s' if tries > 1 else '')) | |
print(f"You Won! {win} Time%s" % ('s' if win > 1 else '')) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment