-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrps.py
30 lines (22 loc) · 785 Bytes
/
rps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import random
def is_valid_play(play):
return play in ['rock', 'paper', 'scissors']
def random_play():
"""vybírá náhodně ze tří možností r, p, s"""
return random.choice(['rock', 'paper', 'scissors'])
def determine_game_result(human, computer):
if human == computer:
return 'tie'
elif human == 'rock' and computer == 'paper' or human == 'scissors' and computer == 'rock' or human == 'paper' and computer == 'scissors':
return 'computer'
else:
return 'human'
def main(input=input):
human = None
while not is_valid_play(human):
human = input('rock, paper or scissors? ')
computer = random_play()
print(computer)
print(determine_game_result(human, computer))
if __name__ == '__main__':
main()