From 4f8e9a7d09ff25f22bf4e33462c843d1bb9607b4 Mon Sep 17 00:00:00 2001 From: sujoypal51 <70856336+sujoypal51@users.noreply.github.com> Date: Sat, 3 Oct 2020 01:06:50 +0530 Subject: [PATCH] Update guess-the-number.py Now THE GAME HAS MORE FEATURE. --- guess-the-number.py | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/guess-the-number.py b/guess-the-number.py index 075314b..6ae5cfb 100644 --- a/guess-the-number.py +++ b/guess-the-number.py @@ -1,18 +1,35 @@ import random -number = random.randint(0, 21) -number_of_guesses = 0 -guess = input('I am thinking of a number between 1 and 20. Guess what number I am thinking of: ') -while number_of_guesses < 6: - number_of_guesses += 1 - if int(guess) == number: - print('Your guess is correct.') - else: - if int(guess) > number: - print('Your guess is greater than the number I am thinking of.') - elif int(guess) < number: - print('Your guess is less than the number I am thinking of.') - guess = input('Guess again!') +while True: + print("I am thinking of a number between 1 and 20. Guess what number I am thinking of") + number = random.randint(1, 20) + chances = 6 + while chances >0: + guess = int(input()) + + if guess == number: + + print("Congratulation YOU WON!!!") + break + + elif guess < number: + print("Your guess was too low: Guess a number higher than", guess) + + else: + print("Your guess was too high: Guess a number lower than", guess) + chances -= 1 + + print("Chances Left: ",chances) + + if not chances < 10: + print("YOU LOSE!!! The number is", number) + + ans = input("Do you want to play again (y/n) : ") + + if ans != 'y': + break + +print("\n T H A N K S F O R P L A Y I N G ! ! ! ! !\n")