-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.1.rockpaperscissorgamewithloops.py
50 lines (42 loc) · 1.52 KB
/
4.1.rockpaperscissorgamewithloops.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
# Rock Paper and Scissor game implementation with user interactive
import sys
import random
from enum import Enum
# Below are the constant remain constant
class RPS(Enum):
ROCK = 1
PAPER = 2
SCISSOR = 3
playagain = True
while playagain:
print("Welcome Rock Paper and Scissor Game".center(50,"*"))
playerChoice = input("Enter...\n1 for Rock\n2 for Paper\n3 for Scissor\n\n")
player = int(playerChoice)
if player < 1 | player > 3:
sys.exit("You must enter 1,2 or 3.")
computerChoice = random.choice("123")
machineChoice = int(computerChoice)
print("-".center(25,"-"))
# Below are accessing Enum constant and also removing RPS as prefix
print("You chose:" + str(RPS(player)).replace("RPS.", "") + ".")
print("Python chose:" + str(RPS(machineChoice)).replace("RPS.", "") + ".")
print("\n")
print("Result of this game is\n")
if player == 1 and machineChoice == 3:
print("🎉🎉🎉 You win!")
elif player == 2 and machineChoice == 1:
print("🎉🎉🎉 You win!")
elif player == 3 and machineChoice == 2:
print("🎉🎉🎉 You win!")
elif player == machineChoice:
print("😲😲😲 Game Tie")
else:
print("🐍🐍🐍 Python wins!")
playagain = input("\n would you like to play again?\nY for Yes\nQ for Quit\n\n")
if playagain.lower() == "y":
continue
else:
print("👋👋👋👋👋 Thanks")
# we can use playagain = False or break
#break
playagain = False