Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created October 7, 2020 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/78f0b98d69667378edc297e87e774bd0 to your computer and use it in GitHub Desktop.
Save codecademydev/78f0b98d69667378edc297e87e774bd0 to your computer and use it in GitHub Desktop.
Codecademy export
hairstyles = ["bouffant", "pixie", "dreadlocks", "crew", "bowl", "bob", "mohawk", "flattop"]
prices = [30, 25, 40, 20, 20, 35, 50, 35]
last_week = [2, 3, 5, 8, 4, 4, 6, 2]
#STEP 1: Creating the variable to store the total price of the hair cuts
total_price = 0
#STEP 2: Iterate through the prices list and add each price to the variable total_price.
for price in prices:
total_price += price
#STEP 3 & 4: After your loop, create a variable called average_price that is the total_price divided by the number of prices. Print the value of the average price
average_price = total_price / len(prices)
print("Average Haircut Price: US$ " + str(average_price))
#STEP 5 & 6: Use a list comprehension to make a list called new_prices, which has each element in prices minus 5. Print new_prices
new_prices = [price - 5 for price in prices]
print(new_prices)
#STEP 7: Create a variable called total_revenue and set it to 0.
total_revenue = 0
#STEP 8, 9 & 10: Use a for loop to create a variable i that goes from 0 to len(hairstyles). Add the product of prices[i] (the price of the haircut at position i) and last_week[i] (the number of people who got the haircut at position i) to total_revenue at each step. Print total_revenue
for i in range(len(hairstyles)):
total_revenue += prices[i] * last_week[i]
print("Total Revenue: US$ " + str(total_revenue))
#STEP 11: Find the average daily revenue by dividing total_revenue by 7. Call this number average_daily_revenue and print it out.
average_daily_revenue = total_revenue / 7
print("Average Daily Revenue: US$ " + str(average_daily_revenue))
#STEP 12 & 13: Advertising all of the haircuts she has that are under 30 dollars using list comprehension. Print the list
cuts_under_30 = [hairstyles[i] for i in range(len(hairstyles)) if new_prices[i] < 30]
print("New promotion ! All these cuts: " + str(cuts_under_30) + " are under US$ 30 !")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment