diff --git a/.gitignore b/.gitignore index 22212bc..e4f969f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,3 @@ *.air *.ipa *.apk - -# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` -# should NOT be excluded as they contain compiler settings and other important -# information for Eclipse / Flash Builder. diff --git a/1-hello-world/01_setting_up.py b/1-hello-world/01_setting_up.py new file mode 100644 index 0000000..4ac8144 --- /dev/null +++ b/1-hello-world/01_setting_up.py @@ -0,0 +1,3 @@ +# Write code below 💖 + +print('Hi') diff --git a/1-hello-world/02_hello_world.py b/1-hello-world/02_hello_world.py new file mode 100644 index 0000000..73fb7c3 --- /dev/null +++ b/1-hello-world/02_hello_world.py @@ -0,0 +1 @@ +print('Hello World!') diff --git a/1-hello-world/pattern.py b/1-hello-world/03_pattern.py similarity index 100% rename from 1-hello-world/pattern.py rename to 1-hello-world/03_pattern.py diff --git a/1-hello-world/initials.py b/1-hello-world/04_initials.py similarity index 92% rename from 1-hello-world/initials.py rename to 1-hello-world/04_initials.py index 57a2076..9e60c6d 100644 --- a/1-hello-world/initials.py +++ b/1-hello-world/04_initials.py @@ -1,4 +1,4 @@ -# Fun fact: My high school band Attica was signed to an indie record label. +# Fun fact: My high school band Attica was signed to an indie record label. 🤘 print(' SSS L ') print('S S L ') diff --git a/1-hello-world/05_letter.py b/1-hello-world/05_letter.py new file mode 100644 index 0000000..e2998bd --- /dev/null +++ b/1-hello-world/05_letter.py @@ -0,0 +1,26 @@ +# Snail Mail 💌 +# Codédex + +print('+---------------------------------------------------------------------------------+') +print('| |') +print('| October 2025 |') +print('| Brooklyn, NY |') +print('| Dear Self, |') +print('| |') +print('| Does great art require suffering? |') +print('| Does great product demand capital? |') +print('| Did you find any truth at the end of the road? |') +print('| |') +print('| Regardless, go build the learning platform you’ve always dreamed of — |') +print('| the one you wish existed when you first started. |') +print('| |') +print('| Give more than you take. |') +print('| Take only what you need. |') +print('| |') +print('| And when things fall apart, get tf back up. |') +print('| |') +print('| - Sonny Li |') +print('| |') +print('| P.S. Hope I made you proud. You got this, kiddo. 🤠 |') +print('| |') +print('+---------------------------------------------------------------------------------+') diff --git a/1-hello-world/05_letter_2.py b/1-hello-world/05_letter_2.py new file mode 100644 index 0000000..d3076b1 --- /dev/null +++ b/1-hello-world/05_letter_2.py @@ -0,0 +1,19 @@ +# Snail Mail 💌 +# Codédex + +print('+---------------------------------------------------------------------+') +print('| |') +print('| |') +print('| Wrote myself a letter |') +print('| just a single question |') +print('| |') +print('| "When you finally get this, where will you be?" ✨ |') +print('| |') +print('| Will you be a shipwreck or a star |') +print('| Falling for a boy who doesn\'t play guitar? |') +print('| Now rewind the tape back to the start |') +print('| |') +print('| - Caroline Polachek |') +print('| |') +print('| |') +print('+---------------------------------------------------------------------+') diff --git a/1-hello-world/hello_world.mov b/1-hello-world/hello_world.mov deleted file mode 100644 index a05b542..0000000 Binary files a/1-hello-world/hello_world.mov and /dev/null differ diff --git a/1-hello-world/hello_world.py b/1-hello-world/hello_world.py deleted file mode 100644 index 60f08aa..0000000 --- a/1-hello-world/hello_world.py +++ /dev/null @@ -1 +0,0 @@ -print('Hello world!') diff --git a/1-hello-world/letter.py b/1-hello-world/letter.py deleted file mode 100644 index fed0003..0000000 --- a/1-hello-world/letter.py +++ /dev/null @@ -1,17 +0,0 @@ -# Snail Mail 💌 -# Codédex - -print('+---------------------------------------------------------------------+') -print('| June 2022 |') -print('| Brooklyn, NY |') -print('| Dear Self, |') -print('| |') -print('| Build the learn to code platform that you always dreamed of. |') -print('| Give more than you take. |') -print('| Care > capital. |') -print('| Five-second funerals for all the Ls. |') -print('| And always get back up. |') -print('| |') -print('| Sonny Li 🤠 |') -print('| |') -print('+---------------------------------------------------------------------+') diff --git a/2-variables/temperature.py b/2-variables/07_temperature.py similarity index 100% rename from 2-variables/temperature.py rename to 2-variables/07_temperature.py diff --git a/2-variables/bmi.py b/2-variables/08_bmi.py similarity index 100% rename from 2-variables/bmi.py rename to 2-variables/08_bmi.py diff --git a/2-variables/09_hypotenuse.py b/2-variables/09_hypotenuse.py new file mode 100644 index 0000000..eb6b9e7 --- /dev/null +++ b/2-variables/09_hypotenuse.py @@ -0,0 +1,9 @@ +# Pythagorean Theorem 📐 +# Codédex + +a = int(input("Enter a: ")) +b = int(input("Enter b: ")) + +c = (a**2 + b**2) ** 0.5 + +print(c) diff --git a/2-variables/quadratic.py b/2-variables/09_quadratic.py similarity index 100% rename from 2-variables/quadratic.py rename to 2-variables/09_quadratic.py diff --git a/2-variables/10_currency.py b/2-variables/10_currency.py new file mode 100644 index 0000000..bb949a1 --- /dev/null +++ b/2-variables/10_currency.py @@ -0,0 +1,10 @@ +# Currency 💵 +# Codédex + +pesos = int(input('What do you have left in pesos? ')) +soles = int(input('What do you have left in soles? ')) +reais = int(input('What do you have left in reais? ')) + +total = pesos * 0.00025 + soles * 0.28 + reais * 0.21 + +print(total) diff --git a/2-variables/currency.py b/2-variables/currency.py deleted file mode 100644 index e66434c..0000000 --- a/2-variables/currency.py +++ /dev/null @@ -1,10 +0,0 @@ -# Currency 💵 -# Codédex - -yuan = int(input('What do you have left in yuan? ')) -yen = int(input('What do you have left in yen? ')) -won = int(input('What do you have left in won? ')) - -total = yuan * 0.15 + yen * 0.0077 + won * 0.00080 - -print(total) diff --git a/3-control-flow/coin_flip.py b/3-control-flow/11_coin_flip.py similarity index 100% rename from 3-control-flow/coin_flip.py rename to 3-control-flow/11_coin_flip.py diff --git a/3-control-flow/grades.py b/3-control-flow/12_grades.py similarity index 100% rename from 3-control-flow/grades.py rename to 3-control-flow/12_grades.py diff --git a/3-control-flow/ph_levels.py b/3-control-flow/13_ph_levels.py similarity index 100% rename from 3-control-flow/ph_levels.py rename to 3-control-flow/13_ph_levels.py diff --git a/3-control-flow/magic_8_ball.py b/3-control-flow/14_magic_8_ball.py similarity index 87% rename from 3-control-flow/magic_8_ball.py rename to 3-control-flow/14_magic_8_ball.py index 0870127..8a620d2 100644 --- a/3-control-flow/magic_8_ball.py +++ b/3-control-flow/14_magic_8_ball.py @@ -3,10 +3,9 @@ import random -question = input('Question: ') +question = input('Question: ') random_number = random.randint(1, 9) -# print(random_number) if random_number == 1: answer = 'Yes - definitely' @@ -29,5 +28,4 @@ else: answer = 'Error' -print('Question: ' + question) print('Magic 8 Ball: ' + answer) diff --git a/3-control-flow/15_the_cyclone_1.py b/3-control-flow/15_the_cyclone_1.py new file mode 100644 index 0000000..fadabd1 --- /dev/null +++ b/3-control-flow/15_the_cyclone_1.py @@ -0,0 +1,14 @@ +# The Cyclone 🎢 +# Codédex + +height = int(input('What is your height (cm)? ')) +credits = int(input('How many credits do you have? ')) + +if height >= 137 and credits >= 10: + print("Enjoy the ride!") +elif height < 137 and credits >= 10: + print("You are not tall enough to ride.") +elif credits < 10 and height >= 137: + print("You don't have enough credits to ride.") +else: + print("You are not tall enough for this ride, nor do you have enough credits.") diff --git a/3-control-flow/15_the_cyclone_2.py b/3-control-flow/15_the_cyclone_2.py new file mode 100644 index 0000000..7a79377 --- /dev/null +++ b/3-control-flow/15_the_cyclone_2.py @@ -0,0 +1,17 @@ +# The Cyclone 🎢 +# Codédex + +ride_is_open = True + +height = int(input('What is your height (cm)? ')) +credits = int(input('How many credits do you have? ')) + +tall_enough = height >= 137 +enough_credits = credits >= 10 + +if ride_is_open and tall_enough and enough_credits: + print("Enjoy the ride!") +elif not tall_enough or not enough_credits: + print("You are either not tall enough to ride or you don't have enough credits.") +else: + print("Sorry! The ride is currently closed!") diff --git a/3-control-flow/sorting_hat.py b/3-control-flow/16_sorting_hat_1.py similarity index 74% rename from 3-control-flow/sorting_hat.py rename to 3-control-flow/16_sorting_hat_1.py index 06437f4..9355579 100644 --- a/3-control-flow/sorting_hat.py +++ b/3-control-flow/16_sorting_hat_1.py @@ -20,11 +20,11 @@ answer = int(input('Enter answer (1-2): ')) if answer == 1: - gryffindor += 1 - ravenclaw += 1 + gryffindor = gryffindor + 1 + ravenclaw = ravenclaw + 1 elif answer == 2: - hufflepuff += 1 - slytherin +=1 + hufflepuff = hufflepuff + 1 + slytherin = slytherin + 1 else: print('Wrong input.') @@ -40,13 +40,13 @@ answer = int(input('Enter your answer (1-4): ')) if answer == 1: - hufflepuff += 1 + hufflepuff = hufflepuff + 2 elif answer == 2: - slytherin +=1 + slytherin = slytherin + 2 elif answer == 3: - ravenclaw +=1 + ravenclaw = ravenclaw + 2 elif answer == 4: - gryffindor +=1 + gryffindor = gryffindor + 2 else: print('Wrong input.') @@ -62,20 +62,22 @@ answer = int(input('Enter your answer (1-4): ')) if answer == 1: - slytherin +=1 + slytherin = slytherin + 4 elif answer == 2: - hufflepuff +=1 + hufflepuff = hufflepuff + 4 elif answer == 3: - ravenclaw +=1 + ravenclaw = ravenclaw + 4 elif answer == 4: - gryffindor +=1 + gryffindor = gryffindor + 4 else: print('Wrong input.') -print(gryffindor) -print(ravenclaw) -print(hufflepuff) -print(slytherin) +print("Gryffindor: ", gryffindor) +print("Ravenclaw: ", ravenclaw) +print("Hufflepuff: ", hufflepuff) +print("Slytherin: ", slytherin) + +# Bonus Part if gryffindor >= ravenclaw and gryffindor >= hufflepuff and gryffindor >= slytherin: print('🦁 Gryffindor!') diff --git a/3-control-flow/16_sorting_hat_2.py b/3-control-flow/16_sorting_hat_2.py new file mode 100644 index 0000000..be56f5c --- /dev/null +++ b/3-control-flow/16_sorting_hat_2.py @@ -0,0 +1,91 @@ +# Sorting Hat 🧙♂️ +# Codédex + +gryffindor = 0 +hufflepuff = 0 +ravenclaw = 0 +slytherin = 0 + +print('===============') +print('The Sorting Hat') +print('===============') + +# ~~~~~~~~~~~~~~~ Question 1 ~~~~~~~~~~~~~~~ + +print('Q1) Do you like Dawn or Dusk?') + +print(' 1) Dawn') +print(' 2) Dusk') + +answer = int(input('Enter answer (1-2): ')) + +if answer == 1: + gryffindor += 1 + ravenclaw += 1 +elif answer == 2: + hufflepuff += 1 + slytherin +=1 +else: + print('Wrong input.') + +# ~~~~~~~~~~~~~~~ Question 2 ~~~~~~~~~~~~~~~ + +print("\nQ2) When I'm dead, I want people to remember me as:") + +print(' 1) The Good') +print(' 2) The Great') +print(' 3) The Wise') +print(' 4) The Bold') + +answer = int(input('Enter your answer (1-4): ')) + +if answer == 1: + hufflepuff += 2 +elif answer == 2: + slytherin += 2 +elif answer == 3: + ravenclaw += 2 +elif answer == 4: + gryffindor += 2 +else: + print('Wrong input.') + +# ~~~~~~~~~~~~~~~ Question 3 ~~~~~~~~~~~~~~~ + +print('\nQ3) Which kind of instrument most pleases your ear?') + +print(' 1) The violin') +print(' 2) The trumpet') +print(' 3) The piano') +print(' 4) The drum') + +answer = int(input('Enter your answer (1-4): ')) + +if answer == 1: + slytherin += 4 +elif answer == 2: + hufflepuff += 4 +elif answer == 3: + ravenclaw +=4 +elif answer == 4: + gryffindor += 4 +else: + print('Wrong input.') + +print("Gryffindor: ", gryffindor) +print("Ravenclaw: ", ravenclaw) +print("Hufflepuff: ", hufflepuff) +print("Slytherin: ", slytherin) + +# Bonus Part + +most_points = max(gryffindor, ravenclaw, hufflepuff, slytherin) # We'll learn about the max() function in Chapter 6 + +if gryffindor == most_points: + print('🦁 Gryffindor!') +elif ravenclaw == most_points: + print('🦅 Ravenclaw!') +elif hufflepuff == most_points: + print('🦡 Hufflepuff!') +else: + print('🐍 Slytherin!') diff --git a/4-loops/enter_pin.py b/4-loops/17_enter_pin.py similarity index 100% rename from 4-loops/enter_pin.py rename to 4-loops/17_enter_pin.py diff --git a/4-loops/guess_number.py b/4-loops/18_guess_number.py similarity index 80% rename from 4-loops/guess_number.py rename to 4-loops/18_guess_number.py index cfbb6c0..1597cad 100644 --- a/4-loops/guess_number.py +++ b/4-loops/18_guess_number.py @@ -5,7 +5,7 @@ tries = 0 while guess != 6 and tries < 5: - guess = int(input('Guess the number: ')) + guess = int(input('Guess the number: ')) tries = tries + 1 if guess != 6: diff --git a/4-loops/detention.py b/4-loops/19_detention.py similarity index 100% rename from 4-loops/detention.py rename to 4-loops/19_detention.py diff --git a/4-loops/99_bottles.py b/4-loops/20_99_bottles.py similarity index 82% rename from 4-loops/99_bottles.py rename to 4-loops/20_99_bottles.py index 428f671..38d7eb3 100644 --- a/4-loops/99_bottles.py +++ b/4-loops/20_99_bottles.py @@ -4,5 +4,5 @@ for i in range(99, 0, -1): print(f'{i} bottles of beer on the wall') print(f'{i} bottles of beer') - print('take one down pass it around') + print('Take one down, pass it around') print(f'{i-1} bottles of beer on the wall') diff --git a/4-loops/fizz_buzz.py b/4-loops/21_fizz_buzz.py similarity index 100% rename from 4-loops/fizz_buzz.py rename to 4-loops/21_fizz_buzz.py diff --git a/5-lists/grocery.py b/5-lists/22_grocery.py similarity index 100% rename from 5-lists/grocery.py rename to 5-lists/22_grocery.py diff --git a/5-lists/todo.py b/5-lists/23_todo.py similarity index 100% rename from 5-lists/todo.py rename to 5-lists/23_todo.py diff --git a/5-lists/24_inventory.py b/5-lists/24_inventory.py new file mode 100644 index 0000000..1c1cb5a --- /dev/null +++ b/5-lists/24_inventory.py @@ -0,0 +1,7 @@ +# Inventory 📦 +# Codédex + +lego_parts = [8980, 7323, 5343, 82700, 92232, 1203, 7319, 8903, 2328, 1279, 679, 589] + +print(min(lego_parts)) +print(max(lego_parts)) diff --git a/5-lists/25_reading_list.py b/5-lists/25_reading_list.py new file mode 100644 index 0000000..07ace1e --- /dev/null +++ b/5-lists/25_reading_list.py @@ -0,0 +1,16 @@ +# Reading List 📚 +# Codédex + +books = ['Harry Potter', + '1984', + 'The Fault in Our Stars', + 'The Mom Test', + 'Life in Code'] + +print(books) + +books.append('Pachinko') +books.remove('The Fault in Our Stars') +books.pop(1) + +print(books) diff --git a/5-lists/mixtape.py b/5-lists/26_mixtape.py similarity index 100% rename from 5-lists/mixtape.py rename to 5-lists/26_mixtape.py diff --git a/5-lists/27_bucket_list.py b/5-lists/27_bucket_list.py new file mode 100644 index 0000000..e734a0a --- /dev/null +++ b/5-lists/27_bucket_list.py @@ -0,0 +1,14 @@ +# Bucket List 🪣 +# Codédex + +things_to_do = [ + '🚀 Build a meaningful product for everyone.', + '⛰ Try out hiking and mountain biking.', + '🌏 Visit at least 10 countries in my lifetime.', + '🎸 Produce an original song.', + '📝 Write a short story.', + '🏃 Finish a 10k marathon.' +] + +for thing in things_to_do: + print(thing) diff --git a/5-lists/bucket_list.py b/5-lists/bucket_list.py deleted file mode 100644 index ea7fae1..0000000 --- a/5-lists/bucket_list.py +++ /dev/null @@ -1,14 +0,0 @@ -# Bucket List: Jerry Zhu -# Codédex - -things_to_do = [ - '🚀 Build a menaingful product for everyone.', - '⛰ Try out hiking and mountain biking.', - '🌏 Visit at least 10 countries in my lifetime.', - '🎸 Produce an original song.', - '📝 Write a short story.', - '🏃 Finish a 10k marathon.' -] - -for thing in things_to_do: - print(thing) diff --git a/5-lists/inventory.py b/5-lists/inventory.py deleted file mode 100644 index 99f001c..0000000 --- a/5-lists/inventory.py +++ /dev/null @@ -1,7 +0,0 @@ -# Inventory 📦 -# Codédex - -airplane_toys = [ 898, 732, 543, 878 ] - -print(min(airplane_toys)) -print(max(airplane_toys)) diff --git a/5-lists/reading.py b/5-lists/reading.py deleted file mode 100644 index 9a9d646..0000000 --- a/5-lists/reading.py +++ /dev/null @@ -1,16 +0,0 @@ -# Reading List 📚 -# Codédex - -books = ['Zero to One', - 'The Lean Startup', - 'The Mom Test', - 'Made to Stick', - 'Life in Code'] - -print(books) - -books.append('Zero to Sold') -books.remove('Zero to One') -books.pop(0) - -print(books) diff --git a/6-functions/dry.py b/6-functions/28_dry.py similarity index 89% rename from 6-functions/dry.py rename to 6-functions/28_dry.py index 162175a..79a4dcf 100644 --- a/6-functions/dry.py +++ b/6-functions/28_dry.py @@ -17,5 +17,5 @@ # This function calculates the length of a list print(len(list_of_foods)) -# This function calculates the a to the power b +# This function calculates a to the power b print(pow(2, 6)) diff --git a/6-functions/fortune_cookie.py b/6-functions/29_fortune_cookie_1.py similarity index 68% rename from 6-functions/fortune_cookie.py rename to 6-functions/29_fortune_cookie_1.py index 15009e2..d82687b 100644 --- a/6-functions/fortune_cookie.py +++ b/6-functions/29_fortune_cookie_1.py @@ -3,7 +3,8 @@ import random -options = ['Don’t pursue happiness – create it.', +options = [ + 'Don’t pursue happiness – create it.', 'All things are difficult before they are easy.', 'The early bird gets the worm, but the second mouse gets the cheese.', 'If you eat something and nobody sees you eat it, it has no calories.', @@ -11,11 +12,13 @@ 'Don’t just think. Act!', 'Your heart will skip a beat.', 'The fortune you search for is in another cookie.', - 'Help! I’m being held prisoner in a Chinese bakery!'] + 'Help! I’m being held prisoner in a Chinese bakery!' +] def fortune(): - print(options[random.randint(0, len(options) - 1)]) + random_fortune = random.randint(0, len(options) - 1) + print(options[random_fortune]) fortune() fortune() -fortune() +fortune() \ No newline at end of file diff --git a/6-functions/29_fortune_cookie_2.py b/6-functions/29_fortune_cookie_2.py new file mode 100644 index 0000000..510b43b --- /dev/null +++ b/6-functions/29_fortune_cookie_2.py @@ -0,0 +1,46 @@ +# Fortune Cookie 🥠 +# Codédex + +import random + +options = [ + 'Don’t pursue happiness – create it.', + 'All things are difficult before they are easy.', + 'The early bird gets the worm, but the second mouse gets the cheese.', + 'If you eat something and nobody sees you eat it, it has no calories.', + 'Someone in your life needs a letter from you.', + 'Don’t just think. Act!', + 'Your heart will skip a beat.', + 'The fortune you search for is in another cookie.', + 'Help! I’m being held prisoner in a Chinese bakery!' +] + +def fortune(): + random_fortune = random.randint(0, len(options) - 1) + + if random_fortune == 0: + option = options[0] + elif random_fortune == 1: + option = options[1] + elif random_fortune == 2: + option = options[2] + elif random_fortune == 3: + option = options[3] + elif random_fortune == 4: + option = options[4] + elif random_fortune == 5: + option = options[5] + elif random_fortune == 6: + option = options[6] + elif random_fortune == 7: + option = options[7] + elif random_fortune == 8: + option = options[8] + else: + option = 'Error' + + print(option) + +fortune() +fortune() +fortune() diff --git a/6-functions/30_rocket.py b/6-functions/30_rocket.py new file mode 100644 index 0000000..d928b41 --- /dev/null +++ b/6-functions/30_rocket.py @@ -0,0 +1,8 @@ +# Mars Orbiter 🚀 +# Codédex + +def distance_to_miles(distance): + miles = distance / 1.609 + print(miles) + +distance_to_miles(10000) diff --git a/6-functions/calculator.py b/6-functions/31_calculator.py similarity index 100% rename from 6-functions/calculator.py rename to 6-functions/31_calculator.py diff --git a/6-functions/32_stonks.py b/6-functions/32_stonks.py new file mode 100644 index 0000000..d2ba9d6 --- /dev/null +++ b/6-functions/32_stonks.py @@ -0,0 +1,23 @@ +# Stonks 📈 +# Codédex + +stock_prices = [34.68, 36.09, 34.94, 33.97, 34.68, 35.82, 43.41, 44.29, 44.65, 53.56, 49.85, 48.71, 48.71, 49.94, 48.53, 47.03, 46.59, 48.62, 44.21, 47.21] + +def price_at(i): + return stock_prices[i-1] + +def max_price(a, b): + mx = 0 + for i in range(a, b + 1): + mx = max(mx, price_at(i)) + return mx + +def min_price(a, b): + mn = price_at(a) + for i in range(a, b + 1): + mn = min(mn, price_at(i)) + return mn + +print(max_price(1, 15)) +print(min_price(5, 10)) +print(price_at(3)) diff --git a/6-functions/drive_thru.py b/6-functions/33_drive_thru.py similarity index 100% rename from 6-functions/drive_thru.py rename to 6-functions/33_drive_thru.py diff --git a/6-functions/rocket.py b/6-functions/rocket.py deleted file mode 100644 index 306c2eb..0000000 --- a/6-functions/rocket.py +++ /dev/null @@ -1,8 +0,0 @@ -# Mars Orbiter 🚀 -# Codédex - -def distance_to_miles(distance): - return distance / 1.609 - -answer = distance_to_miles(10000) -print(answer) diff --git a/6-functions/stonks.py b/6-functions/stonks.py deleted file mode 100644 index 862e8c3..0000000 --- a/6-functions/stonks.py +++ /dev/null @@ -1,23 +0,0 @@ -# Stonks 📈 -# Codédex - -stock_prices = [ 95.91, 93.8, 94.38, 96.27, 96.42, 95.54, 95.13, 93.89, 90.11, 91.05, 92.39, 95.23, 95.87, 96.35, 95.96, 97.44, 96.58, 98.23, 98.64, 100.72 ] - -def price_at(i): - return stock_prices[i-1] - -def max_price(a, b): - mx = 0 - for i in range(a, b): - mx = max(mx, price_at(i)) - return mx - -def min_price(a, b): - mn = price_at(a) - for i in range(a, b): - mn = min(mn, price_at(i)) - return mn - -print(max_price(1, 21)) -print(min_price(10, 20)) -print(price_at(3)) diff --git a/7-classes-objects/34_restaurants.py b/7-classes-objects/34_restaurants.py new file mode 100644 index 0000000..3986bfe --- /dev/null +++ b/7-classes-objects/34_restaurants.py @@ -0,0 +1,8 @@ +# Restaurants 🍽️ +# Codédex + +class Restaurant: + name = '' + category = '' + rating = 0.0 + delivery = True diff --git a/7-classes-objects/35_bobs_burgers.py b/7-classes-objects/35_bobs_burgers.py new file mode 100644 index 0000000..68264cc --- /dev/null +++ b/7-classes-objects/35_bobs_burgers.py @@ -0,0 +1,30 @@ +# Bob's Burgers 🍔 +# Codédex + +class Restaurant: + name = '' + type = '' + rating = 0.0 + delivery = False + +bobs_burgers = Restaurant() +bobs_burgers.name = 'Bob\'s Burgers' +bobs_burgers.type = 'American Diner' +bobs_burgers.rating = 4.2 +bobs_burgers.delivery = False + +katz_deli = Restaurant() +katz_deli.name = 'Katz\'s Deli' +katz_deli.type = 'Kosher Deli' +katz_deli.rating = 4.5 +katz_deli.delivery = True + +baekjeong = Restaurant() +baekjeong.name = 'Baekjeong NYC' +baekjeong.type = 'Korean BBQ' +baekjeong.rating = 4.4 +baekjeong.delivery = False + +print(vars(bobs_burgers)) +print(vars(katz_deli)) +print(vars(baekjeong)) \ No newline at end of file diff --git a/7-classes-objects/36_favorite_cities.py b/7-classes-objects/36_favorite_cities.py new file mode 100644 index 0000000..138e0ac --- /dev/null +++ b/7-classes-objects/36_favorite_cities.py @@ -0,0 +1,17 @@ +# Favorite Cities 🏙️ +# Codédex + +class City: + def __init__(self, name, country, population, landmarks): + self.name = name + self.country = country + self.population = population + self.landmarks = landmarks + + +nyc = City("New York City", "USA", 8468000, ["Statue of Liberty", "Brooklyn Bridge", "Apollo Theatre"]) + +shanghai = City("Shanghai", "China", 26320000, ["The Bund", "Jin Mao Tower", "Tianzifang"]) + +print(vars(nyc)) +print(vars(shanghai)) diff --git a/7-classes-objects/37_bank_accounts.py b/7-classes-objects/37_bank_accounts.py new file mode 100644 index 0000000..59feb9c --- /dev/null +++ b/7-classes-objects/37_bank_accounts.py @@ -0,0 +1,32 @@ +# Bank Accounts 🏦 +# Codédex + +class BankAccount: + def __init__(self, first_name, last_name, account_id, account_type, pin, balance): + self.first_name = first_name + self.last_name = last_name + self.account_id = account_id + self.account_type = account_type + self.pin = pin + self.balance = balance + + def deposit(self, amount): + self.balance = self.balance + amount + return self.balance + + def withdraw(self, amount): + self.balance = self.balance - amount + return self.balance + + def display_balance(self): + print(f"${self.balance}") + +checking_account = BankAccount("Jane", "Doe", 13243546, "checking", 0000, 250.00) + +checking_account.deposit(100) + +checking_account.display_balance() + +checking_account.withdraw(50) + +checking_account.display_balance() diff --git a/7-classes-objects/38_pokedex_1.py b/7-classes-objects/38_pokedex_1.py new file mode 100644 index 0000000..f11d4a1 --- /dev/null +++ b/7-classes-objects/38_pokedex_1.py @@ -0,0 +1,39 @@ +# Pokédex 📟 +# Codédex + +# Class definition +class Pokemon: + def __init__(self, entry, name, types, description, is_caught): + self.entry = entry + self.name = name + self.types = types + self.description = description + self.is_caught = is_caught + + def speak(self): + print(self.name + ', ' + self.name + '!') + + def display_details(self): + print('Entry Number: ' + str(self.entry)) + print('Name: ' + self.name) + + if len(self.types) == 1: + print('Type: ' + self.types[0]) + else: + print('Type: ' + self.types[0] + '/' + self.types[1]) + + print('Description: ' + self.description) + + if self.is_caught: + print(self.name + ' has already been caught!') + else: + print(self.name + ' hasn\'t been caught yet.') + +# Pokémon objects +pikachu = Pokemon(25, 'Pikachu', ['Electric'], 'It has small electric sacs on both its cheeks. If threatened, it looses electric charges from the sacs.', True) +charizard = Pokemon(6, 'Charizard', ['Fire', 'Flying'], 'It spits fire that is hot enough to melt boulders. It may cause forest fires by blowing flames.', False) +gyarados = Pokemon(130, 'Gyarados', ['Water', 'Flying'], 'It has an extremely aggressive nature. The HYPER BEAM it shoots from its mouth totally incinerates all targets.', False) + +pikachu.speak() +charizard.speak() +gyarados.speak() \ No newline at end of file diff --git a/7-classes-objects/38_pokedex_2.py b/7-classes-objects/38_pokedex_2.py new file mode 100644 index 0000000..91c3311 --- /dev/null +++ b/7-classes-objects/38_pokedex_2.py @@ -0,0 +1,43 @@ +# Pokédex 📟 +# Codédex + +# Class definition +class Pokemon: + def __init__(self, entry, name, types, description, level, region, is_caught): + self.entry = entry + self.name = name + self.types = types + self.description = description + self.level = level + self.region = region + self.is_caught = is_caught + + def speak(self): + print(self.name + ', ' + self.name + '!') + + def display_details(self): + print('Entry Number: ' + str(self.entry)) + print('Name: ' + self.name) + + if len(self.types) == 1: + print('Type: ' + self.types[0]) + else: + print('Type: ' + self.types[0] + '/' + self.types[1]) + + print('Lv. ' + str(self.level)) + print('Region: ' + self.region) + print('Description: ' + self.description) + + if self.is_caught: + print(self.name + ' has already been caught!') + else: + print(self.name + ' hasn\'t been caught yet.') + +# Pokémon objects +pikachu = Pokemon(25, 'Pikachu', ['Electric'], 'It has small electric sacs on both its cheeks. If threatened, it looses electric charges from the sacs.', 25, 'Kanto', True) +charizard = Pokemon(6, 'Charizard', ['Fire', 'Flying'], 'It spits fire that is hot enough to melt boulders. It may cause forest fires by blowing flames.', 36, 'Kanto', False) +gyarados = Pokemon(130, 'Gyarados', ['Water', 'Flying'], 'It has an extremely aggressive nature. The HYPER BEAM it shoots from its mouth totally incinerates all targets.', 57, 'Kanto', False) + +pikachu.speak() +charizard.speak() +gyarados.speak() \ No newline at end of file diff --git a/8-modules/39_slot_machine_1.py b/8-modules/39_slot_machine_1.py new file mode 100644 index 0000000..70fc1fc --- /dev/null +++ b/8-modules/39_slot_machine_1.py @@ -0,0 +1,19 @@ +# Slot Machine 🎰 +# Codédex + +import random + +symbols = [ + '🍒', + '🍇', + '🍉', + '7️⃣' +] + +results = random.choices(symbols, k=3) +print(f'{results[0]} | {results[1]} | {results[2]}') + +if (results[0] == '7️⃣' and results[1] == '7️⃣' and results[2] == '7️⃣'): + print('Jackpot! 💰') +else: + print('Thanks for playing!') diff --git a/8-modules/39_slot_machine_2.py b/8-modules/39_slot_machine_2.py new file mode 100644 index 0000000..6b5cb8b --- /dev/null +++ b/8-modules/39_slot_machine_2.py @@ -0,0 +1,31 @@ +# Slot Machine 🎰 +# Codédex + +import random + +symbols = [ + '🍒', + '🍇', + '🍉', + '7️⃣' +] + +def play(): + + for i in range(1, 51): + results = random.choices(symbols, k=3) + print(f'{results[0]} | {results[1]} | {results[2]}') + win = results[0] == '7️⃣' and results[1] == '7️⃣' and results[2] == '7️⃣' + + if win: + print('Jackpot!!! 💰') + break + else: + results = random.choices(symbols, k=3) + +answer = '' +while answer.upper() != 'N': + play() + answer = input('Keep playing? (Y/N) ') + +print('Thanks for playing!') \ No newline at end of file diff --git a/8-modules/40_solar_system.py b/8-modules/40_solar_system.py new file mode 100644 index 0000000..7388ce0 --- /dev/null +++ b/8-modules/40_solar_system.py @@ -0,0 +1,32 @@ +# Solar System 🪐 +# Codédex + +from math import pi; from random import choice as ch + +planets = [ + 'Mercury', + 'Venus', + 'Earth', + 'Mars', + 'Saturn' +] + +random_planet = ch(planets) +radius = 0 + +if random_planet == 'Mercury': + radius = 2440 +elif random_planet == 'Venus': + radius = 6052 +elif random_planet == 'Earth': + radius = 6371 +elif random_planet == 'Mars': + radius = 3390 +elif random_planet == 'Saturn': + radius = 58232 +else: + print('Oops! An error occurred.') + +planet_area = 4 * pi * radius * radius + +print(f'Area of {random_planet}: {planet_area} sq mi') diff --git a/8-modules/41_bday_messages.py b/8-modules/41_bday_messages.py new file mode 100644 index 0000000..02659fb --- /dev/null +++ b/8-modules/41_bday_messages.py @@ -0,0 +1,14 @@ +# Countdown 🎂 +# Codédex + +import random + +bday_messages = [ + 'Hope you have a very Happy Birthday! 🎈', + 'It\'s your special day – get out there and celebrate! 🎉', + 'You were born and the world got better – everybody wins! Happy Birthday! 🥳', + 'Have lots of fun on your special day! 🎂', + 'Another year of you going around the sun! 🌞' +] + +random_message = random.choice(bday_messages) \ No newline at end of file diff --git a/8-modules/41_main.py b/8-modules/41_main.py new file mode 100644 index 0000000..42cd469 --- /dev/null +++ b/8-modules/41_main.py @@ -0,0 +1,15 @@ +# Countdown 🎂 +# Codédex + +import datetime, bday_messages + +today = datetime.date.today() + +my_next_birthday = datetime.date(2023, 4, 5) + +days_away = my_next_birthday - today + +if my_next_birthday == today: + print(bday_messages.random_message) +else: + print(f'My next birthday is {days_away.days} days away!') diff --git a/8-modules/42_forty_two.py b/8-modules/42_forty_two.py new file mode 100644 index 0000000..7e5928e --- /dev/null +++ b/8-modules/42_forty_two.py @@ -0,0 +1,6 @@ +# Forty Two 4️⃣2️⃣ +# Codédex + +import wikipedia + +print(wikipedia.search('Philosophy of life')) \ No newline at end of file diff --git a/8-modules/43_zen.py b/8-modules/43_zen.py new file mode 100644 index 0000000..60c1fe9 --- /dev/null +++ b/8-modules/43_zen.py @@ -0,0 +1,26 @@ +# The Zen of Python 📜 +# Codédex + +import this + +""" +Beautiful is better than ugly. +Explicit is better than implicit. +Simple is better than complex. +Complex is better than complicated. +Flat is better than nested. +Sparse is better than dense. +Readability counts. +Special cases aren't special enough to break the rules. +Although practicality beats purity. +Errors should never pass silently. +Unless explicitly silenced. +In the face of ambiguity, refuse the temptation to guess. +There should be one-- and preferably only one --obvious way to do it. +Although that way may not be obvious at first unless you're Dutch. +Now is better than never. +Although never is often better than *right* now. +If the implementation is hard to explain, it's a bad idea. +If the implementation is easy to explain, it may be a good idea. +Namespaces are one honking great idea -- let's do more of those! +""" diff --git a/README.md b/README.md index 7d99c14..79b47b8 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,87 @@