This is all I have of the code, so far you can play rock, paper, scissors and see who wins or loses. I need help making a scoring system. Best two out of three is the final winner. Also I need help with how I would rerun the game until one of the players gets 2 points. Right now, the user has to manually type yes to replay the game which I would be fine with I just cant figure out how I would keep score.
JavaScript
x
71
71
1
#ROCK PAPER SCISSOR
2
import random
3
4
while True:
5
# variables
6
rpc = ["rock","paper","scissor"]
7
player = None
8
player_score = 0
9
comp_score = 0
10
11
# player and comp choice
12
while player not in (rpc):
13
player = input("rock, paper, or scissor: ").lower()
14
15
comp = random.choice(rpc)
16
17
print("Rock, Paper, or Scissor?: ")
18
19
# player wins or loses
20
if player == comp:
21
print("player: ", player)
22
print("computer: ", comp)
23
print("TIE!")
24
25
elif player == "rock":
26
if comp == "paper":
27
print("player: ", player)
28
print("computer: ", comp)
29
print("YOU LOSE!")
30
comp_score = 1
31
if comp == "scissor":
32
print("player: ", player)
33
print("computer: ", comp)
34
print("YOU WIN!")
35
player_score = 1
36
37
elif player == "scissor":
38
if comp == "rock":
39
print("player: ", player)
40
print("computer: ", comp)
41
print("YOU LOSE!")
42
comp_score = 1
43
if comp == "paper":
44
print("player: ", player)
45
print("computer: ", comp)
46
print("YOU WIN!")
47
player_score = 1
48
49
elif player == "paper":
50
if comp == "scissor":
51
print("player: ", player)
52
print("computer: ", comp)
53
print("YOU LOSE!")
54
comp_score = 1
55
if comp == "rock":
56
print("player: ", player)
57
print("computer: ", comp)
58
print("YOU WIN!")
59
player_score = 1
60
61
#Score
62
print("your score:", player_score)
63
print("computers score: ", comp_score)
64
65
player_choice = input("keep playing?: yes/no").lower()
66
67
if player_choice == "no":
68
break
69
70
print("Goodbye")
71
Advertisement
Answer
JavaScript
1
75
75
1
#ROCK PAPER SCISSOR
2
import random
3
4
player_score = 0
5
comp_score = 0
6
7
while True:
8
# variables
9
rpc = ["rock","paper","scissor"]
10
player = None
11
12
# player and comp choice
13
while player not in (rpc):
14
player = input("rock, paper, or scissor: ").lower()
15
16
comp = random.choice(rpc)
17
18
# player wins or loses
19
if player == comp:
20
print("player: ", player)
21
print("computer: ", comp)
22
print("TIE!")
23
24
elif player == "rock":
25
if comp == "paper":
26
print("player: ", player)
27
print("computer: ", comp)
28
print("YOU LOSE!")
29
comp_score += 1
30
if comp == "scissor":
31
print("player: ", player)
32
print("computer: ", comp)
33
print("YOU WIN!")
34
player_score += 1
35
36
elif player == "scissor":
37
if comp == "rock":
38
print("player: ", player)
39
print("computer: ", comp)
40
print("YOU LOSE!")
41
comp_score += 1
42
if comp == "paper":
43
print("player: ", player)
44
print("computer: ", comp)
45
print("YOU WIN!")
46
player_score += 1
47
48
elif player == "paper":
49
if comp == "scissor":
50
print("player: ", player)
51
print("computer: ", comp)
52
print("YOU LOSE!")
53
comp_score += 1
54
if comp == "rock":
55
print("player: ", player)
56
print("computer: ", comp)
57
print("YOU WIN!")
58
player_score += 1
59
60
#Score
61
print("your score:", player_score)
62
print("computers score: ", comp_score)
63
64
# player_choice = input("keep playing?: yes/no").lower()
65
66
if player_score == 2:
67
print("player wins")
68
break
69
70
elif comp_score == 2:
71
print("computer wins")
72
break
73
74
print("Goodbye")
75