From 036bce9806aa1a0716b1c583f66ff0680f85768b Mon Sep 17 00:00:00 2001 From: EduardPrigoana Date: Sun, 13 Apr 2025 20:54:27 +0300 Subject: [PATCH] Add py/random/RandomChoice.py --- py/random/RandomChoice.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 py/random/RandomChoice.py diff --git a/py/random/RandomChoice.py b/py/random/RandomChoice.py new file mode 100644 index 0000000..dec8ee4 --- /dev/null +++ b/py/random/RandomChoice.py @@ -0,0 +1,25 @@ +import random + +# Seed the random number generator +random.seed() + +# Start the loop +loop = True +while loop: + # Generate a random number between 0 and 5 + computer_choice = random.randint(0, 5) + + # Ask the user for input + try: + user_choice = int(input("Please input a number from 0 to 5: ")) + + if 0 <= user_choice <= 5: + if computer_choice == user_choice: + print("Nice! You guessed it!") + loop = False + else: + print(f"Nope! Computer chose {computer_choice}. Try again.") + else: + print("Please enter a valid number between 0 and 5.") + except ValueError: + print("That's not a number! Please enter a number between 0 and 5.")