-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrockpaperscessiorgame.py
More file actions
52 lines (42 loc) · 1.41 KB
/
rockpaperscessiorgame.py
File metadata and controls
52 lines (42 loc) · 1.41 KB
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
import random
def Game():
shapes = ["rock", "paper", "scissors"]
userwin = 0
computerwin = 0
while True:
randomnum = random.randint(0, 2)
computer = shapes[randomnum]
player = input("Enter rock, paper or scissors (q to quit): ").lower()
if player == "q":
break
if player not in shapes:
print("Invalid choice, try again.")
continue
print("You chose:", player)
print("Computer chose:", computer)
if (player == "rock" and computer == "scissors") or \
(player == "paper" and computer == "rock") or \
(player == "scissors" and computer == "paper"):
print("You won!")
userwin += 1
elif player == computer:
print("Game Tie")
else:
print("You lost")
computerwin += 1
print(f"Score: You = {userwin}, Computer = {computerwin}\n")
print("\n Final Result:")
print(f"You: {userwin} | Computer: {computerwin}")
if userwin > computerwin:
print(" Congratulations! You are the winner.")
elif userwin < computerwin:
print(" Computer wins!")
else:
print("It's a tie!")
while True:
wannaplay = input("Do you wanna play? (yes/no): ").lower()
if wannaplay == "yes":
Game()
else:
print("Goodbye")
break