Https://www.codecademy.com/paths/computer-science/tracks/cspath-flow-data-iteration/modules/dspath-python-loops/projects/carlys-clippers

File “script.py”, line 27, in
cuts_under_30 = [hairstyles[i] for i in range(len(hairstyles)) if new_prices[i] < 30]
File “script.py”, line 27, in
cuts_under_30 = [hairstyles[i] for i in range(len(hairstyles)) if new_prices[i] < 30]
TypeError: ‘int’ object is not subscriptable

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]

total_price = 0
for price in prices:
  total_price += price
  
average_price = total_price/ len(prices)
print('Average Haircut Price: ' + str(average_price))

for price in prices:
  new_prices = price - 5
  print(new_prices)
  
total_revenue = 0
for i in range(0, len(hairstyles)):
  total_revenue += prices[i] * last_week[i]

print("Total Revenue: " + "<"+str(total_revenue)+">")

average_daily_revenue = total_revenue/7
print(average_daily_revenue)
  
cuts_under_30 = [hairstyles[i] for i in range(len(hairstyles)) if new_prices[i] < 30]
print(cuts_under_30)

In your for loop you wrote

So new_prices is an int, not an array.

1 Like