File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33
44import random
55
6- slot_machine_symbols = [
6+ symbols = [
77 '🍒' ,
88 '🍇' ,
99 '🍉' ,
1010 '7️⃣'
1111]
1212
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️⃣'
13+ def play ():
14+ results = random .choices (symbols , k = 3 )
15+ win = results [0 ] == '7️⃣' and results [1 ] == '7️⃣' and results [2 ] == '7️⃣'
1616
17- while not all_sevens :
17+ for i in range ( 50 ) :
1818 print (f'{ results [0 ]} | { results [1 ]} | { results [2 ]} ' )
19- all_sevens = results [0 ] == '7️⃣' and results [1 ] == '7️⃣' and results [2 ] == '7️⃣'
19+ win = results [0 ] == '7️⃣' and results [1 ] == '7️⃣' and results [2 ] == '7️⃣'
2020
21- if all_sevens :
21+ if win :
2222 print ("Jackpot!!! 💰" )
23+ break
2324 else :
24- results = random .choices (slot_machine_symbols , k = 3 )
25- answer = "Y"
25+ results = random .choices (symbols , k = 3 )
2626
27+ answer = "Y"
2728while answer .upper () != "N" :
28- play_slots ()
29+ play ()
2930 answer = input ("Keep playing? (Y/N) " )
3031
3132print ("Thanks for playing!" )
Original file line number Diff line number Diff line change 66bday_messages = [
77 'Hope you have a very Happy Birthday! 🎈' ,
88 'It\' s your special day – get out there and celebrate!' ,
9- 'You were born and the world got better – everybody wins! Happy Birthday!'
9+ 'You were born and the world got better – everybody wins! Happy Birthday!' ,
10+ 'Another year of you going around the sun! 🌞'
1011]
1112
1213today = datetime .date .today ()
1314
14- my_birthday = datetime .date (2023 , 4 , 5 )
15+ my_next_birthday = datetime .date (2023 , 4 , 5 )
1516
16- days_away = my_birthday - today
17+ days_away = my_next_birthday - today
1718
18- if my_birthday == today :
19- print (random .choice (bday_messages ))
19+ if my_next_birthday == today :
20+ print (random .choice (bday_messages ))
2021else :
21- print (f'My birthday is { days_away } away!' )
22+ print (f'My next birthday is { days_away } away!' )
Original file line number Diff line number Diff line change 1+ # Solar System 🪐
2+ # Codédex
3+
4+ from math import pi
5+ from random import choice as ch
6+
7+ planets = [
8+ 'Mercury' ,
9+ 'Venus' ,
10+ 'Earth' ,
11+ 'Mars' ,
12+ 'Saturn'
13+ ]
14+
15+ random_planet = ch (planets )
16+ radius = 0
17+
18+ if random_planet == 'Mercury' :
19+ radius = 2440
20+ elif random_planet == 'Venus' :
21+ radius = 6052
22+ elif random_planet == 'Earth' :
23+ radius = 6371
24+ elif random_planet == 'Mars' :
25+ radius = 3390
26+ elif random_planet == 'Saturn' :
27+ radius = 58232
28+ else :
29+ print ('Oops! An error occurred.' )
30+
31+ planet_area = 4 * pi * radius * radius
32+
33+ print (f'Area of { random_planet } : { planet_area } km2' )
Original file line number Diff line number Diff line change 1+ # Forty Two 4️⃣2️⃣
2+ # Codédex
3+
4+ import wikipedia
5+
6+ print (wikipedia .search ('Philosophy of life' ))
Original file line number Diff line number Diff line change 1+ # Zen of Python 🐍
2+ # Codédex
3+
4+ import this
5+
6+ """
7+ Beautiful is better than ugly.
8+ Explicit is better than implicit.
9+ Simple is better than complex.
10+ Complex is better than complicated.
11+ Flat is better than nested.
12+ Sparse is better than dense.
13+ Readability counts.
14+ Special cases aren't special enough to break the rules.
15+ Although practicality beats purity.
16+ Errors should never pass silently.
17+ Unless explicitly silenced.
18+ In the face of ambiguity, refuse the temptation to guess.
19+ There should be one-- and preferably only one --obvious way to do it.
20+ Although that way may not be obvious at first unless you're Dutch.
21+ Now is better than never.
22+ Although never is often better than *right* now.
23+ If the implementation is hard to explain, it's a bad idea.
24+ If the implementation is easy to explain, it may be a good idea.
25+ Namespaces are one honking great idea -- let's do more of those!
26+ """
You can’t perform that action at this time.
0 commit comments