diff --git a/1-hello-world/02_hello_world.py b/1-hello-world/02_hello_world.py index 60f08aa..73fb7c3 100644 --- a/1-hello-world/02_hello_world.py +++ b/1-hello-world/02_hello_world.py @@ -1 +1 @@ -print('Hello world!') +print('Hello World!') diff --git a/2-variables/09_hypotenuse.py b/2-variables/09_hypotenuse.py index 9b1894f..72c4d27 100644 --- a/2-variables/09_hypotenuse.py +++ b/2-variables/09_hypotenuse.py @@ -1,8 +1,8 @@ # Pythagorean Theroem 📐 # Codédex -a = int(input("Enter a: ")) -b = int(input("Enter b: ")) +a = int(input("Enter the length of a: ")) +b = int(input("Enter the length of b: ")) c = (a**2 + b**2) ** 0.5 diff --git a/3-control-flow/14_magic_8_ball.py b/3-control-flow/14_magic_8_ball.py index 539b5f4..790fe74 100644 --- a/3-control-flow/14_magic_8_ball.py +++ b/3-control-flow/14_magic_8_ball.py @@ -3,7 +3,7 @@ import random -question = input() +question = input('Is Codédex better than Udemy yet? ') # Replace with your own question random_number = random.randint(1, 9) diff --git a/3-control-flow/15_the_cyclone_1.py b/3-control-flow/15_the_cyclone.py similarity index 82% rename from 3-control-flow/15_the_cyclone_1.py rename to 3-control-flow/15_the_cyclone.py index fadabd1..c9f375d 100644 --- a/3-control-flow/15_the_cyclone_1.py +++ b/3-control-flow/15_the_cyclone.py @@ -11,4 +11,4 @@ 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.") + print("You have not met either requirement.") diff --git a/3-control-flow/15_the_cyclone_2.py b/3-control-flow/15_the_cyclone_2.py deleted file mode 100644 index 7a79377..0000000 --- a/3-control-flow/15_the_cyclone_2.py +++ /dev/null @@ -1,17 +0,0 @@ -# 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/16_sorting_hat_2.py b/3-control-flow/16_sorting_hat_2.py index 55692c1..86c9540 100644 --- a/3-control-flow/16_sorting_hat_2.py +++ b/3-control-flow/16_sorting_hat_2.py @@ -24,7 +24,7 @@ ravenclaw += 1 elif answer == 2: hufflepuff += 1 - slytherin +=1 + slytherin += 1 else: print('Wrong input.') @@ -84,4 +84,4 @@ elif hufflepuff >= slytherin: print('🦡 Hufflepuff!') else: - print('🐍 Slytherin!') \ No newline at end of file + print('🐍 Slytherin!') diff --git a/5-lists/24_inventory.py b/5-lists/24_inventory.py index 99f001c..1c1cb5a 100644 --- a/5-lists/24_inventory.py +++ b/5-lists/24_inventory.py @@ -1,7 +1,7 @@ # Inventory 📦 # Codédex -airplane_toys = [ 898, 732, 543, 878 ] +lego_parts = [8980, 7323, 5343, 82700, 92232, 1203, 7319, 8903, 2328, 1279, 679, 589] -print(min(airplane_toys)) -print(max(airplane_toys)) +print(min(lego_parts)) +print(max(lego_parts)) diff --git a/5-lists/25_reading_list.py b/5-lists/25_reading_list.py index 9a9d646..3876923 100644 --- a/5-lists/25_reading_list.py +++ b/5-lists/25_reading_list.py @@ -4,7 +4,7 @@ books = ['Zero to One', 'The Lean Startup', 'The Mom Test', - 'Made to Stick', + 'Make It Stick', 'Life in Code'] print(books) diff --git a/5-lists/27_bucket_list.py b/5-lists/27_bucket_list.py index ea7fae1..4b37e13 100644 --- a/5-lists/27_bucket_list.py +++ b/5-lists/27_bucket_list.py @@ -1,13 +1,13 @@ -# Bucket List: Jerry Zhu +# Bucket List: Jerry Zhu (Codédex Intern) 💭 # Codédex things_to_do = [ - '🚀 Build a menaingful product for everyone.', - '⛰ Try out hiking and mountain biking.', + '🏃 Finish a 10k marathon.', + '📝 Publish a short story.', '🌏 Visit at least 10 countries in my lifetime.', + '🚲 Try out mountain biking.', '🎸 Produce an original song.', - '📝 Write a short story.', - '🏃 Finish a 10k marathon.' + '🚀 Build a meaningful product for everyone.', ] for thing in things_to_do: diff --git a/6-functions/28_dry.py b/6-functions/28_dry.py index 79a4dcf..a95505a 100644 --- a/6-functions/28_dry.py +++ b/6-functions/28_dry.py @@ -3,19 +3,19 @@ import random -list_of_foods = ['celery', 'broccoli', 'cabbage'] +coffee_menu = ['drip coffee', 'cold brew', 'cappuccino', 'latte', 'mocha', 'espresso'] # This was the first function introduced in the course -print('Hello, World!') +print('Hello World!') -# This function calculates the maximum of two numbers a and b +# This function calculates the maximum of two numbers print(max(3, 5)) -# This function calculates the minimum of two numbers a and b +# This function calculates the minimum of two numbers print(min(-1, 7)) # This function calculates the length of a list -print(len(list_of_foods)) +print(len(coffee_menu)) # This function calculates a to the power b print(pow(2, 6)) diff --git a/6-functions/29_fortune_cookie_1.py b/6-functions/29_fortune_cookie_1.py index d82687b..39d9c9e 100644 --- a/6-functions/29_fortune_cookie_1.py +++ b/6-functions/29_fortune_cookie_1.py @@ -7,7 +7,6 @@ '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.', @@ -16,9 +15,31 @@ ] def fortune(): - random_fortune = random.randint(0, len(options) - 1) - print(options[random_fortune]) + random_fortune = random.randint(0, 7) + 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() -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 index 510b43b..d55a196 100644 --- a/6-functions/29_fortune_cookie_2.py +++ b/6-functions/29_fortune_cookie_2.py @@ -7,7 +7,6 @@ '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.', @@ -16,30 +15,8 @@ ] 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) + random_fortune = random.randint(0, 7) + print(options[random_fortune]) fortune() fortune() diff --git a/6-functions/30_rocket.py b/6-functions/30_rocket.py index 306c2eb..3f87c5c 100644 --- a/6-functions/30_rocket.py +++ b/6-functions/30_rocket.py @@ -2,7 +2,6 @@ # Codédex def distance_to_miles(distance): - return distance / 1.609 + print(distance / 1.609) -answer = distance_to_miles(10000) -print(answer) +distance_to_miles(10000) diff --git a/6-functions/32_stonks.py b/6-functions/32_stonks.py index 7290ebc..af4fe34 100644 --- a/6-functions/32_stonks.py +++ b/6-functions/32_stonks.py @@ -1,10 +1,7 @@ # Stonks 📈 # Codédex -stock_prices = [ 6.15, 5.81, 5.70, 5.65, 5.33, 5.62, 5.19, 6.13, 7.20, 7.34, 7.95, 7.53, 7.39, 7.59, 7.27 ] - -def price_at(i): - return stock_prices[i-1] +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 max_price(a, b): mx = 0 @@ -18,6 +15,9 @@ def min_price(a, b): mn = min(mn, price_at(i)) return mn +def price_at(i): + return stock_prices[i-1] + print(max_price(1, 15)) print(min_price(5, 10)) print(price_at(3)) diff --git a/6-functions/33_drive_thru.py b/6-functions/33_drive_thru.py index 04a1aa3..48f2a8e 100644 --- a/6-functions/33_drive_thru.py +++ b/6-functions/33_drive_thru.py @@ -1,29 +1,29 @@ # Drive-Thru 🚙 # Codédex - + def get_item(x): if x == 1: - return '🍔 Cheeseburger' + return '🍔 Double-Double' elif x == 2: - return '🍟 Fries' + return '🍔 Cheeseburger' elif x == 3: - return '🥤 Soda' + return '🍔 Hamburger' elif x == 4: - return '🍦 Ice Cream' + return '🍟 French Fries' elif x == 5: - return '🍪 Cookie' + return '🥛 Shakes' else: return "invalid option" def welcome(): - print('Welcome to Sonnyboy\'s Diner!') - print('Here\'s the menu:') - print('1. 🍔 Cheeseburger') - print('2. 🍟 Fries') - print('3. 🥤 Soda') - print('4. 🍦 Ice Cream') - print('5. 🍪 Cookie') - + print('Welcome to In-N-Out Burger!') + print('Here\'s the menu:\n') + print('1️⃣ 🍔 Double-Double $5.15') + print('2️⃣ 🍔 Cheeseburger $3.65') + print('3️⃣ 🍔 Hamburger $3.25') + print('4️⃣ 🍟 French Fries $2.20') + print('5️⃣ 🥛 Shakes $2.85\n') + welcome() option = int(input('What would you like to order? ')) diff --git a/7-classes-objects/34_restaurants.py b/7-classes-objects/34_restaurants.py index b8e1299..3986bfe 100644 --- a/7-classes-objects/34_restaurants.py +++ b/7-classes-objects/34_restaurants.py @@ -3,6 +3,6 @@ class Restaurant: name = '' - description = '' + category = '' rating = 0.0 - deliver = True + delivery = True diff --git a/7-classes-objects/35_bobs_burgers.py b/7-classes-objects/35_bobs_burgers.py index c174dcb..ea30822 100644 --- a/7-classes-objects/35_bobs_burgers.py +++ b/7-classes-objects/35_bobs_burgers.py @@ -3,24 +3,28 @@ class Restaurant: name = '' - type = '' + category = '' rating = 0.0 delivery = False bobs_burgers = Restaurant() bobs_burgers.name = 'Bob\'s Burgers' -bobs_burgers.type = 'American Diner' +bobs_burgers.category = '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.category = 'Kosher Deli' katz_deli.rating = 4.5 katz_deli.delivery = True baekjeong = Restaurant() baekjeong.name = 'Baekjeong NYC' -baekjeong.type = 'Korean BBQ' +baekjeong.category = 'Korean BBQ' baekjeong.rating = 4.4 baekjeong.delivery = False + +print(vars(bobs_burgers)) +print(vars(katz_deli)) +print(vars(baekjeong)) diff --git a/7-classes-objects/36_favorite_cities.py b/7-classes-objects/36_favorite_cities.py index 138e0ac..600c975 100644 --- a/7-classes-objects/36_favorite_cities.py +++ b/7-classes-objects/36_favorite_cities.py @@ -8,7 +8,6 @@ def __init__(self, name, country, population, landmarks): 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"]) diff --git a/7-classes-objects/38_pokedex.py b/7-classes-objects/38_pokedex.py index efe04f2..68d06c6 100644 --- a/7-classes-objects/38_pokedex.py +++ b/7-classes-objects/38_pokedex.py @@ -11,11 +11,9 @@ def __init__(self, name, type, description, level, region, is_caught): self.region = region self.is_caught = is_caught - # Instance method def speak(self): - print(self.name + ' made a sound!') + print(self.name + ', ' + self.name + '!') - # Instance method def display_details(self): print('Name: ' + self.name) @@ -34,8 +32,6 @@ def display_details(self): print(self.name + ' hasn\'t been caught yet.') # Pokémon objects -pikachu = Pokemon("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("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("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 = Pokemon('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('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('Gyarados', ['Water', 'Flying'], 'It has an extremely aggressive nature. The HYPER BEAM it shoots from its mouth totally incinerates all targets.', 57, 'Kanto', False) diff --git a/8-modules/39_slot_machine_1.py b/8-modules/39_slot_machine_1.py index 70fc1fc..14ffd0e 100644 --- a/8-modules/39_slot_machine_1.py +++ b/8-modules/39_slot_machine_1.py @@ -14,6 +14,6 @@ print(f'{results[0]} | {results[1]} | {results[2]}') if (results[0] == '7️⃣' and results[1] == '7️⃣' and results[2] == '7️⃣'): - print('Jackpot! 💰') + print('Jackpot! 💰') else: - print('Thanks for playing!') + print('Thanks for playing!') diff --git a/8-modules/39_slot_machine_2.py b/8-modules/39_slot_machine_2.py index 6b5cb8b..14d406a 100644 --- a/8-modules/39_slot_machine_2.py +++ b/8-modules/39_slot_machine_2.py @@ -11,21 +11,19 @@ ] def play(): + 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️⃣' - for i in range(1, 51): + if win: + print('Jackpot!!! 💰') + else: 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 +print('Thanks for playing!') diff --git a/8-modules/40_solar_system.py b/8-modules/40_solar_system.py index 7388ce0..198791e 100644 --- a/8-modules/40_solar_system.py +++ b/8-modules/40_solar_system.py @@ -1,7 +1,8 @@ # Solar System 🪐 # Codédex -from math import pi; from random import choice as ch +from math import pi +from random import choice as ch planets = [ 'Mercury', @@ -29,4 +30,4 @@ planet_area = 4 * pi * radius * radius -print(f'Area of {random_planet}: {planet_area} sq mi') +print(f'Area of {random_planet}: {planet_area} km²') diff --git a/8-modules/41_bday_messages.py b/8-modules/41_bday_messages.py index 02659fb..4ce9d58 100644 --- a/8-modules/41_bday_messages.py +++ b/8-modules/41_bday_messages.py @@ -6,9 +6,9 @@ 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! 🥳', + 'You were born and the world got better – everybody wins! 🥳', '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 +random_message = random.choice(bday_messages) diff --git a/8-modules/41_main.py b/8-modules/41_main.py index 42cd469..0e78b22 100644 --- a/8-modules/41_main.py +++ b/8-modules/41_main.py @@ -5,11 +5,11 @@ today = datetime.date.today() -my_next_birthday = datetime.date(2023, 4, 5) +next_birthday = datetime.date(2023, 4, 5) -days_away = my_next_birthday - today +days_away = next_birthday - today -if my_next_birthday == today: +if 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 index 7e5928e..a83d493 100644 --- a/8-modules/42_forty_two.py +++ b/8-modules/42_forty_two.py @@ -1,6 +1,6 @@ -# Forty Two 4️⃣2️⃣ +# Forty Two 🔮 # Codédex import wikipedia -print(wikipedia.search('Philosophy of life')) \ No newline at end of file +print(wikipedia.summary('Philosophy of life')) diff --git a/README.md b/README.md index 6c3fc75..809ed13 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@
-Welcome to The Legend of Python GitHub repo! We are super excited to have you. Here, you will find all the solutions to the Codédex exercises. Feel free to make pull requests to add your own twists on the exercises! +Welcome to [The Legend of Python](https://www.codedex.io/python) GitHub repo! We are super excited to have you. Here, you will find all the solutions to the Codédex exercises. Feel free to make pull requests to add your own twists on the exercises! -### Website: www.codedex.io +### Website: www.codedex.io/python ## Hello World diff --git a/projects.md b/projects.md index 20fd964..8b43416 100644 --- a/projects.md +++ b/projects.md @@ -4,8 +4,8 @@ - 🥠 Fortune Cookie - 🎲 Dice Rolling Simulator -- 🫱 Rock Paper Scisssors -- 🫱 Rock Paper Scissors Lizard Spark +- 🫱 Rock Paper Scissors +- 🫱 Rock Paper Scissors Lizard Spock - 🤑 Who Wants to Be a Millionaire - ❓ Quiz Game - ⚔️ Text-Based Adventure