Skip to content

Commit 3efd214

Browse files
committed
Added lesson 14
1 parent 007ea90 commit 3efd214

4 files changed

Lines changed: 137 additions & 0 deletions

File tree

β€ŽREADME.mdβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@
6767
- πŸ”— [Chapter 11 - Scope](https://github.com/gitdagray/python-course/tree/main/lesson11)
6868
- πŸ”— [Chapter 12 - Closures](https://github.com/gitdagray/python-course/tree/main/lesson12)
6969
- πŸ”— [Chapter 13 - f-Strings](https://github.com/gitdagray/python-course/tree/main/lesson13)
70+
- πŸ”— [Chapter 14 - Modules](https://github.com/gitdagray/python-course/tree/main/lesson14)

β€Žlesson14/kansas.pyβ€Ž

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from random import choice
2+
3+
capital = "Topeka"
4+
5+
bird = "Western Meadowlark"
6+
7+
flower = "Sunflower"
8+
9+
song = "Home on the Range"
10+
11+
12+
def randomfunfact():
13+
funfacts = [
14+
"Kansas is considered flat, but it does have a mountain.",
15+
"Wichita is the largest city in the state, but many would guess that it is Kansas City.",
16+
"A considerable portion of Kansas City is actually in Missouri.",
17+
"Most Kansans are annoyed by Wizard of Oz references from people outside of Kansas."
18+
]
19+
20+
index = choice("0123")
21+
22+
print(funfacts[int(index)])
23+
24+
25+
if __name__ == "__main__":
26+
randomfunfact()

β€Žlesson14/modules.pyβ€Ž

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
3+
from math import pi
4+
import sys
5+
import random as rdm
6+
from enum import Enum
7+
import kansas
8+
from rps7 import rock_paper_scissors
9+
10+
print(pi)
11+
12+
# for item in dir(rdm):
13+
# print(item)
14+
15+
print(kansas.capital)
16+
kansas.randomfunfact()
17+
18+
print(__name__)
19+
print(kansas.__name__)
20+
21+
rock_paper_scissors()

β€Žlesson14/rps7.pyβ€Ž

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import sys
2+
import random
3+
from enum import Enum
4+
5+
6+
def rps():
7+
game_count = 0
8+
player_wins = 0
9+
python_wins = 0
10+
11+
def play_rps():
12+
nonlocal player_wins
13+
nonlocal python_wins
14+
15+
class RPS(Enum):
16+
ROCK = 1
17+
PAPER = 2
18+
SCISSORS = 3
19+
20+
playerchoice = input(
21+
"\nEnter... \n1 for Rock,\n2 for Paper, or \n3 for Scissors:\n\n")
22+
23+
if playerchoice not in ["1", "2", "3"]:
24+
print("You must enter 1, 2, or 3.")
25+
return play_rps()
26+
27+
player = int(playerchoice)
28+
29+
computerchoice = random.choice("123")
30+
31+
computer = int(computerchoice)
32+
33+
print(f"\nYou chose {str(RPS(player)).replace('RPS.', '').title()}.")
34+
print(
35+
f"Python chose {str(RPS(computer)).replace('RPS.', '').title()}.\n"
36+
)
37+
38+
def decide_winner(player, computer):
39+
nonlocal player_wins
40+
nonlocal python_wins
41+
if player == 1 and computer == 3:
42+
player_wins += 1
43+
return "πŸŽ‰ You win!"
44+
elif player == 2 and computer == 1:
45+
player_wins += 1
46+
return "πŸŽ‰ You win!"
47+
elif player == 3 and computer == 2:
48+
player_wins += 1
49+
return "πŸŽ‰ You win!"
50+
elif player == computer:
51+
return "😲 Tie game!"
52+
else:
53+
python_wins += 1
54+
return "🐍 Python wins!"
55+
56+
game_result = decide_winner(player, computer)
57+
58+
print(game_result)
59+
60+
nonlocal game_count
61+
game_count += 1
62+
63+
print(f"\nGame count: {str(game_count)}")
64+
print(f"\nPlayer wins: {str(player_wins)}")
65+
print(f"\nPython wins: {str(python_wins)}")
66+
67+
print("\nPlay again?")
68+
69+
while True:
70+
playagain = input("\nY for Yes or \nQ to Quit\n")
71+
if playagain.lower() not in ["y", "q"]:
72+
continue
73+
else:
74+
break
75+
76+
if playagain.lower() == "y":
77+
return play_rps()
78+
else:
79+
print("\nπŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰")
80+
print("Thank you for playing!\n")
81+
sys.exit("Bye! πŸ‘‹")
82+
83+
return play_rps
84+
85+
86+
rock_paper_scissors = rps()
87+
88+
if __name__ == "__main__":
89+
rock_paper_scissors()

0 commit comments

Comments
Β (0)