-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01.rockpaperscissor.py
executable file
·75 lines (62 loc) · 1.91 KB
/
01.rockpaperscissor.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
# Type: project
# Teaches: loops, conditionals, input
#
# Goal: As simple as possible. No exceptions, lists, functions, etc
import random
score_random = 0
score_user = 0
while True:
limit = int(input("Play to which score limit (>0)? "))
if limit > 0:
break
while score_random < limit and score_user < limit:
tie = "Tie! No points"
win_user = "User wins!"
win_random = "Computer wins!"
rps = ["rock", "paper", "scissor"]
choice_random = random.choice(rps)
while True:
choice_user = input("\nPlay which [rock, paper, scissor]? ")
if ( choice_user == "rock"
or choice_user == "paper"
or choice_user == "scissor"
):
break
print("Computer picked: ", choice_random)
if choice_random == "rock":
if choice_user == "rock":
print(tie)
elif choice_user == "paper":
print(win_user)
score_user += 1
elif choice_user == "scissor":
print(win_random)
score_random += 1
elif choice_random == "paper":
if choice_user == "rock":
print(win_random)
score_random += 1
elif choice_user == "paper":
print(tie)
elif choice_user == "scissor":
print(win_user)
score_user += 1
elif choice_random == "scissor":
if choice_user == "rock":
print(win_user)
score_user += 1
elif choice_user == "paper":
print(win_random)
score_random += 1
elif choice_user == "scissor":
print(tie)
print("\nThe computer has: ", score_random, " points")
print("The user has: ", score_user, " points")
print("\nGame over: ", end="")
if score_user == score_random:
print("both players are tied")
elif score_user < score_random:
print("computer wins")
else:
print("user wins")