Hi I am in Carly's Clippers and I keep getting a error

LINK: https://www.codecademy.com/courses/learn-python-3/projects/python-carlys-clippers
I keep getting this error:

*raceback (most recent call last):

  • File “script.py”, line 31, in *
  • for i in range(len(hairstyles)) *
  • File “script.py”, line 32, in *
  • if new_prices[i] < 30*
    TypeError: ‘generator’ object is not subscriptable

it is in the 12th thing you need to my code for this is
cuts_under_30 = [hairstyles[i] for i in range(len(hairstyles)) if range(len(new_prices) -1) < 30]

The issue I found happens after the if statement, when I remove it the code works and for the life of me I cant figure out why I keep getting this error I tried a lot of altering the way I did the code but I keep getting this error, but I cant get the code working with the if statement.

Also I tried to look at the video you get with it and it is the same from what I can see.

P.S. this is my full Code

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]

#Make a total price Variable

total_price = 0

for price in prices:

#Make a total of all the prices in list prices

total_price = total_price + price

#Make avarage of prices in list prices

avarage_price = total_price / len(prices)

print(“Avarage Haircut Prices:”, avarage_price)

new_prices = (new -5 for new in prices)

print(“New Prices:”, list(new_prices))

#Calculate total revenue

total_revenue = 0

for i in range(len(hairstyles)):

total_revenue += prices[i] * last_week[i]

#Total revenue

print(“Total Revenue:”, total_revenue)

#Avarage of week

avarage_daily_revenue = total_revenue / 7

print(avarage_daily_revenue)

#Make list of haircuts under 30$

cuts_under_30 = [hairstyles[i] for i in range(len(hairstyles)) if range(len(new_prices[i]) -1) < 30]

print(list(cuts_under_30))

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility


When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile:

new_prices isn’t a list here because you used ( and ) instead of [ and ]
It should be
new_prices = [new - 5 for new in prices]
or you could do
new_prices = list(new -5 for new in prices)

1 Like

Got to be honest when you explained that I had a bit of a facepalm moment. Aldo I did not think Phyton would allow that. I am curious what the program saw it as? But thank you very much for showing that error :slight_smile:

by itself,
new - 5 for new in prices
is a generator (which is a kind of iterator … an object that makes iteration possible)

1 Like