-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRock.py
More file actions
119 lines (101 loc) · 2.67 KB
/
Rock.py
File metadata and controls
119 lines (101 loc) · 2.67 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""
Rock, Paper, Scissors Game
-------------------------------------------
How to play:
1.You will play against the computer.
2.On each round, type Rock, Paper, or Scissors (case-insensitive).
3.The computer will randomly choose as well.
4. The winner is decided by the standard rules:
Rock beats Scissors
Scissors beats Paper
Paper beats Rock
- Type 'exit' anytime to quit the game.
Nirattay Biswas
"""
import random
#choices available
choices=["rock","paper","scissors"]
def menu():
print("\nWelcome to Rock,Paper,Scissors!")
print("Rules: Rock beats Scissors, Scissors beats Paper, Paper beats Rock.")
print("Play Rock, Paper, or Scissors.")
print("Type 'exit' to quit anytime.\n")
ASCII_ART = {
"rock": """
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
""",
"paper": """
___
---' ____)____
______)
_______)
_______)
---.__________)
""",
"scissors": """
_______
---' ____)____
______)
__________)
(____)
---.__(___)
"""
}
def player():
while(True):
ch=input("Your choice:").strip().lower()
if(ch=="exit"):
return ch
if(ch in choices):
return ch
else:
print("Invalid input.PLease enter Rock, Paper, or Scissors.")
def computer():
return random.choice(choices)
def determine_winner(playerc,computerc):
if(playerc==computerc):
return "tie"
elif ((playerc == "rock" and computerc == "scissors") or
(playerc== "scissors" and computerc == "paper") or
(playerc == "paper" and computerc == "rock")):
return "player"
else:
return "computer"
def play_game():
wins=losses=ties=0
menu()
while(True):
ply=player()
if(ply=="exit"):
break
comp=computer()
print("\nYou choose")
print(ASCII_ART[ply])
print("Computer chose:")
print(ASCII_ART[comp])
result=determine_winner(ply,comp)
if result == "tie":
print(" It's a tie!")
ties += 1
elif result == "player":
print("You win this round!")
wins += 1
else:
print("Computer wins this round!")
losses += 1
print(f"Score---> Wins: {wins}, Losses: {losses}, Ties: {ties}\n")
print("\nThanks for playing Rock, Paper, Scissors!")
print(f"Score → Wins: {wins}, Losses: {losses}, Ties: {ties}\n")
if wins > losses:
print(" Winner: You!")
elif wins < losses:
print(" Winner: Computer!")
else:
print(" Its a tie !")
if __name__ == "__main__":
play_game()