-
Notifications
You must be signed in to change notification settings - Fork 0
/
rps.py
47 lines (39 loc) · 1.65 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
import random
# Store all possibilities in a list all functions can access
from typing import List
options: list[str] = ["rock", "paper", "scissors"]
def info():
# return possible options
answer: str = "the possibilities are " + options
return answer
def play(pinput):
# check if the players input is valid
if pinput in options:
n = len(options)
r = random.randint(0, n - 1)
binput = options[r]
# check for winner
if pinput == "rock" and binput == "rock":
return "I chose " + binput + ", noone won!"
if pinput == "rock" and binput == "paper":
return "I chose " + binput + ", I won!"
if pinput == "rock" and binput == "scissors":
return "I chose " + binput + ", you won!"
if pinput == "paper" and binput == "rock":
return "I chose " + binput + ", you won!"
if pinput == "paper" and binput == "paper":
return "I chose " + binput + ", noone won!!"
if pinput == "paper" and binput == "scissors":
return "I chose " + binput + ", I won!"
if pinput == "scissors" and binput == "rock":
return "I chose " + binput + ", I won"
if pinput == "scissors" and binput == "paper":
return "I chose " + binput + ", you won!!"
if pinput == "scissors" and binput == "scissors":
return "I chose " + binput + ", noone won!"
else:
answer = "something weird happened"
return answer
else:
answer = 'Something is off here, did you check you submitted your choice in lower case and it is one of ' + options + '?'