Skip to content

Commit 1256a06

Browse files
committed
Added lesson 5
1 parent 5ee5a12 commit 1256a06

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

β€Žlesson05/rps.pyβ€Ž

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
import random
3+
from enum import Enum
4+
5+
6+
class RPS(Enum):
7+
ROCK = 1
8+
PAPER = 2
9+
SCISSORS = 3
10+
11+
12+
print("")
13+
playerchoice = input(
14+
"Enter...\n1 for Rock,\n2 for Paper, or \n3 for Scissors:\n\n")
15+
16+
player = int(playerchoice)
17+
18+
if player < 1 | player > 3:
19+
sys.exit("You must enter 1, 2, or 3.")
20+
21+
computerchoice = random.choice("123")
22+
23+
computer = int(computerchoice)
24+
25+
print("")
26+
print("You chose " + str(RPS(player)).replace('RPS.', '') + ".")
27+
print("Python chose " + str(RPS(computer)).replace('RPS.', '') + ".")
28+
print("")
29+
30+
if player == 1 and computer == 3:
31+
print("πŸŽ‰ You win!")
32+
elif player == 2 and computer == 1:
33+
print("πŸŽ‰ You win!")
34+
elif player == 3 and computer == 2:
35+
print("πŸŽ‰ You win!")
36+
elif player == computer:
37+
print("😲 Tie game!")
38+
else:
39+
print("🐍 Python wins!")

0 commit comments

Comments
Β (0)