the-honk/gcse computer science/year 9/python challenges/10 - RPS.py

25 lines
566 B
Python
Raw Normal View History

2021-05-28 20:38:55 +00:00
import random
# 0: rock
# 1: paper
# 2: scissors
rps = ['rock', 'paper', 'scissors']
cpu = random.randint(0, 2)
user = str.lower(input('Rock, paper, or scissors?'))
user = rps.index(user)
print('Computer: ', rps[cpu])
print('User: ', rps[user])
# if it is a tie
if ((cpu == 0) & (user == 0)) | ((cpu == 1) & (user == 1)) | ((cpu == 2) & (user == 2)):
print('It was a tie!')
exit()
# if the computer wins
elif ((cpu == 1) & (user == 0)) | ((cpu == 0) & (user == 2)) | ((cpu == 2) & (user == 1)):
print('Computer wins!')
else:
print('User wins!')