From 18dc6ae0966416b0eddb2472a467718f1e3a0412 Mon Sep 17 00:00:00 2001 From: PP6975H <52664716+PP6975H@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:33:32 +0530 Subject: [PATCH] Update guessinggame.py --- .../guessinggame.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/practices/ch06-organizing-code-with-functions/guessinggame.py b/practices/ch06-organizing-code-with-functions/guessinggame.py index f919ba7..9dd94de 100644 --- a/practices/ch06-organizing-code-with-functions/guessinggame.py +++ b/practices/ch06-organizing-code-with-functions/guessinggame.py @@ -12,16 +12,19 @@ attempts = 0 while attempts < attempt_limit: - guess_text = input("How many M&Ms are in the jar? ") - guess = int(guess_text) - attempts += 1 + try: + guess_text = input("How many M&Ms are in the jar? ") + guess = int(guess_text) + attempts += 1 - if mm_count == guess: - print(f"You got a free lunch! It was {guess}.") - break - elif guess < mm_count: - print("Sorry, that's too LOW!") - else: - print("That's too HIGH!") + if mm_count == guess: + print(f"You got a free lunch! It was {guess}.") + break + elif guess < mm_count: + print("Sorry, that's too LOW!") + else: + print("That's too HIGH!") -print(f"Bye, you're done in {attempts}!") + print(f"Bye, you're done in {attempts}!") + except: + print("Enter an integer Value !")