RosettaCodeData/Task/Rock-paper-scissors/Python/rock-paper-scissors-1.py

23 lines
829 B
Python
Raw Permalink Normal View History

2015-02-20 00:35:01 -05:00
from random import choice
2013-04-10 23:57:08 -07:00
2015-02-20 00:35:01 -05:00
rules = {'rock': 'paper', 'scissors': 'rock', 'paper': 'scissors'}
previous = ['rock', 'paper', 'scissors']
2013-04-10 23:57:08 -07:00
while True:
2015-02-20 00:35:01 -05:00
human = input('\nchoose your weapon: ')
computer = rules[choice(previous)] # choose the weapon which beats a randomly chosen weapon from "previous"
2013-04-10 23:57:08 -07:00
2015-02-20 00:35:01 -05:00
if human in ('quit', 'exit'): break
2013-04-10 23:57:08 -07:00
2015-02-20 00:35:01 -05:00
elif human in rules:
previous.append(human)
print('the computer played', computer, end='; ')
2013-04-10 23:57:08 -07:00
2015-02-20 00:35:01 -05:00
if rules[computer] == human: # if what beats the computer's choice is the human's choice...
print('yay you win!')
elif rules[human] == computer: # if what beats the human's choice is the computer's choice...
print('the computer beat you... :(')
2015-11-18 06:14:39 +00:00
else: print("it's a tie!")
2013-04-10 23:57:08 -07:00
2015-02-20 00:35:01 -05:00
else: print("that's not a valid choice")