Add py/random/RandomChoice.py
This commit is contained in:
parent
a03e114459
commit
036bce9806
1 changed files with 25 additions and 0 deletions
25
py/random/RandomChoice.py
Normal file
25
py/random/RandomChoice.py
Normal 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.")
|
Loading…
Add table
Reference in a new issue