diff --git a/code/05-interactive-code/m-n-m/guessinggame.py b/code/05-interactive-code/m-n-m/guessinggame.py index f919ba7..3bd7889 100644 --- a/code/05-interactive-code/m-n-m/guessinggame.py +++ b/code/05-interactive-code/m-n-m/guessinggame.py @@ -12,16 +12,18 @@ 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!") - -print(f"Bye, you're done in {attempts}!") + if mm_count == guess: + print(f"You got a free lunch! It was {guess}.") + print(f"Bye, you're done in {attempts}!") + break + elif guess < mm_count: + print("Sorry, that's too LOW!") + else: + print("That's too HIGH!") + except: + print("Invalid keyword!\nEnter an integer value ")