Add py/random/RandomChoice.py

This commit is contained in:
Eduard Prigoana 2025-04-13 20:54:27 +03:00
parent a03e114459
commit 036bce9806

25
py/random/RandomChoice.py Normal file
View file

@ -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.")