Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e408c9

Browse filesBrowse files
committed
Solutions for challenges 39 & 40 (TLoP)
1 parent 02f9900 commit 9e408c9
Copy full SHA for 9e408c9

File tree

Expand file treeCollapse file tree

2 files changed

+52
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+52
-0
lines changed

‎8-modules/39_slot_machine.py

Copy file name to clipboard
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Slot Machine 🎰
2+
# Codédex
3+
4+
import random
5+
6+
slot_machine_symbols = [
7+
'🍒',
8+
'🍇',
9+
'🍉',
10+
'7️⃣'
11+
]
12+
13+
def play_slots():
14+
results = random.choices(slot_machine_symbols, k=3)
15+
all_sevens = results[0] == '7️⃣' and results[1] == '7️⃣' and results[2] == '7️⃣'
16+
17+
while not all_sevens:
18+
print(f'{results[0]} | {results[1]} | {results[2]}')
19+
all_sevens = results[0] == '7️⃣' and results[1] == '7️⃣' and results[2] == '7️⃣'
20+
21+
if all_sevens:
22+
print("Jackpot!!! 💰")
23+
else:
24+
results = random.choices(slot_machine_symbols, k=3)
25+
answer = "Y"
26+
27+
while answer.upper() != "N":
28+
play_slots()
29+
answer = input("Keep playing? (Y/N) ")
30+
31+
print("Thanks for playing!")

‎8-modules/40_birthday_card.py

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Birthday Card 🎂
2+
# Codédex
3+
4+
import random, datetime
5+
6+
bday_messages = [
7+
'Hope you have a very Happy Birthday! 🎈',
8+
'It\'s your special day – get out there and celebrate!',
9+
'You were born and the world got better – everybody wins! Happy Birthday!'
10+
]
11+
12+
today = datetime.date.today()
13+
14+
my_birthday = datetime.date(2023, 4, 5)
15+
16+
days_away = my_birthday - today
17+
18+
if my_birthday == today:
19+
print(random.choice(bday_messages))
20+
else:
21+
print(f'My birthday is {days_away} away!')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.