Skip to content

Commit 155a1a5

Browse files
committed
Added lesson 10
1 parent ad33543 commit 155a1a5

4 files changed

Lines changed: 85 additions & 0 deletions

File tree

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@
6363
- πŸ”— [Chapter 7 - Dictionaries & Sets](https://github.com/gitdagray/python-course/tree/main/lesson07)
6464
- πŸ”— [Chapter 8 - While Loops & For Loops](https://github.com/gitdagray/python-course/tree/main/lesson08)
6565
- πŸ”— [Chapter 9 - Functions](https://github.com/gitdagray/python-course/tree/main/lesson09)
66+
- πŸ”— [Chapter 10 - Recursion](https://github.com/gitdagray/python-course/tree/main/lesson10)

β€Žlesson10/example.pyβ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
value = "y"
2+
count = 0
3+
4+
while value:
5+
count += 1
6+
print(count)
7+
if (count == 5):
8+
break
9+
else:
10+
value = 0
11+
continue

β€Žlesson10/recursion.pyβ€Ž

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
3+
def add_one(num):
4+
5+
if (num >= 9):
6+
return num + 1
7+
8+
total = num + 1
9+
print(total)
10+
11+
return add_one(total)
12+
13+
14+
mynewtotal = add_one(0)
15+
print(mynewtotal)

β€Žlesson10/rps3.pyβ€Ž

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import sys
2+
import random
3+
from enum import Enum
4+
5+
6+
def play_rps():
7+
8+
class RPS(Enum):
9+
ROCK = 1
10+
PAPER = 2
11+
SCISSORS = 3
12+
13+
playerchoice = input(
14+
"\nEnter... \n1 for Rock,\n2 for Paper, or \n3 for Scissors:\n\n")
15+
16+
if playerchoice not in ["1", "2", "3"]:
17+
print("You must enter 1, 2, or 3.")
18+
return play_rps()
19+
20+
player = int(playerchoice)
21+
22+
computerchoice = random.choice("123")
23+
24+
computer = int(computerchoice)
25+
26+
print("\nYou chose " + str(RPS(player)).replace('RPS.', '').title() + ".")
27+
print("Python chose " + str(RPS(computer)
28+
).replace('RPS.', '').title() + ".\n")
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!")
40+
41+
print("\nPlay again?")
42+
43+
while True:
44+
playagain = input("\nY for Yes or \nQ to Quit\n")
45+
if playagain.lower() not in ["y", "q"]:
46+
continue
47+
else:
48+
break
49+
50+
if playagain.lower() == "y":
51+
return play_rps()
52+
else:
53+
print("\nπŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰")
54+
print("Thank you for playing!\n")
55+
sys.exit("Bye! πŸ‘‹")
56+
57+
58+
play_rps()

0 commit comments

Comments
Β (0)