Play Rock Paper Scissors Online: Simple Game Code
Welcome to Rock Paper Scissors!
Create a list of options
choices = ['rock', 'paper', 'scissors']
Get user input
user_choice = input('Rock, paper, or scissors? ').lower()
Check for valid input
if user_choice in choices: # Generate computer choice import random computer_choice = random.choice(choices) print('Computer chooses: ' + computer_choice)
# Compare choices
if user_choice == computer_choice:
print('It's a tie!')
elif user_choice == 'rock':
if computer_choice == 'paper':
print('Computer wins!')
else:
print('You win!')
elif user_choice == 'paper':
if computer_choice == 'rock':
print('You win!')
else:
print('Computer wins!')
elif user_choice == 'scissors':
if computer_choice == 'rock':
print('Computer wins!')
else:
print('You win!')
Invalid input
else: print('Invalid input, try again.')
原文地址: https://www.cveoy.top/t/topic/lmnr 著作权归作者所有。请勿转载和采集!