Untitled
unknown
python
24 days ago
1.1 kB
5
Indexable
Never
import random def generate_random_number(): random_number = random.randint(1, 100) return random_number def guess_number_game(): x = 0 random_number = generate_random_number() while x < 10: try: user_entry = int(input("Guess the number from 1 to 100:")) x = x + 1 if user_entry == random_number: print(f"Good job! Number of guesses: {x}") break if random_number < user_entry < 101: print("Overshot the mark!") if 0 < user_entry < random_number: print("Undershot the mark!") if 1 > user_entry or user_entry > 100: print("Invalid Input! Please input a number from 1 to 100!") x = x - 1 if x == 10: print("Sorry, no more guesses!") print(f"Random number was: {random_number}") except ValueError: print("Invalid Input! Please input a number from 1 to 100!") if __name__ == "__main__": guess_number_game()
Leave a Comment