An error or am I going mental

In Carly’s clippers in python loops project.

The instructions in the list do not match the video , and the error is repeated again in the instructions at the end

I don’t know if I’m going crazy or not, those are much smarter people than I am so I’m struggling but it looks to me like they give the wrong range parameters.

for i in range(len(hairstyles)-1):
total_revenue += prices[i] * last_week[i]

prices and last_week and hair_styles are 8 long but the range is going to return [0,1,2,3,4,5,6]

If I’m correct than this is just ridiculous. The only way to check my work is to compare the results with the instructor in the video but it looks to me like he is 70 short in total revenue.

Or I’m missing something and I’m ranting for no reason lol. I’m very green to coding .

Can you give your full code? We need to know the whole thing so we can help you.
Also use these symbols (```) to put your code. It keeps the forums tidy and clean :wink:

That’s probably wrong yes. (And by probably I mean I don’t have testable code for your particular case with expected/actual result)

Generally you want to avoid indices altogether and instead say something like “iterate through all of these” because that’s not possible to get wrong. The zip function could help you iterate over multiple iterables at the same time, alternatively you’d group the data for each entry into one object so that it’s all in one place (which is exactly what zip would accomplish)

This is entirely correctly written by the way (think about it):

You can use range() in your list comprehension to make i go from 0 to len(new_prices) - 1 .

Well this not about the code it’s about the video and instructions being misleading.
But this is my code which i think is correct. Check total revenue calculation to see the problem.

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 i in prices:
  total_price += i
  
average_price = total_price / len(prices)

print("Average Haircut Price: " + str(average_price))

new_prices = [price -5 for price in prices]

print(new_prices)

total_revenue = 0

# in the video the instructor writes range(len(hairstyles)-1)
for i in range(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(new_prices)) if new_prices[i] < 30]

print(cuts_under_30)

test_array = [i for i in range(len(hairstyles))]
print(test_array)

test_array_minus_one = [i for i in range(len(hairstyles)-1)]
print(test_array_minus_one)

*flicks through the video* yeah. video is wrong. instructions are correct.

On the other hand, it’s inconsistent with this one:

Use a for loop to create a variable i that goes from 0 to len(hairstyles)

Because they use the same wording but don’t subtract 1

Comes down to whether “to” is considered inclusive or not, it’s ambiguous

So I’m mental then lol

the arrays we are iterating are 8 long

range(hairstyles) will return [0,1,2,3,4,5,6,7]

range(hairstyles)-1) will return [0,1,2,3,4,5,6] which is off by one as far as I understand

There is another len-1 at the last instruction

So to sum up it looks like the instructions are good in total revenue calculation but the video is not and in the last instruction they are both wrong ?

Since they say it differently in two places, the instructions are wrong too. Individually they’re both correct because they’re ambiguous. The video is absolutely wrong, because it’s off by 1.

As programmers we need to reason about it in whatever format is comfortable, and then look up how various things actually behave, such as where range stops (or, again, better yet: use semantics that simply say “all of these”)

2 Likes

Ugh, quite annoying. I hope the people making these things for novice programmers pay attention to what they’re doing, it’s just horrible when they don’t synchronize the code and what they’re saying

1 Like

This lesson issue has been referred upstairs a couple times in the past. That makes three exercises with this ambiguity.

The author seems to be reminding us that the range is one less than the length, and for their effort have gained lots of people’s pain. A problem easily solved once somebody gets around to it.

2 Likes

YESS!!! I absolutely freaked out yesterday doing this. No matter what i did i was throwing syntax errors. Made me think “If I can’t figure something out that is still technically a beginner project, then how will i make it in the coding field.” I’ve worked 8 hours a day for a week to run into this, sodiscouraging i almost quit. But i believe as aspiring programmers, we will have to deal with this stuff and be able to trouble shoot. So now i’m here and am SO GRATEFUL for this forum, showed me i was not alone with the annoyances from this project.

I messaged codecademy and let them know about it and they agreed that the video ‘got ahead of its self’ Because of the method .format() Which was not introduced. Now that i see that you follow one or the other, i understand what was going on. THANK YOU.

2 Likes

Why, you’re welcome :slight_smile:

Actually, you should give @mtf the credit, he’s the one who originally said that :smile:

2 Likes

I feel your pain silver-strings :smile:
I guess this is just a life of a programmer.
You got thru it and didn’t give up. That is what matters. There is always an answer.

Stay skeptical and trust no one :smile:

Du di du du di du, para ra ra ra pa pa (X-files reference for those younger of us :smile: )

2 Likes

You’re right, my bad. @mtf Thank you!!

@kedlaw lololol Yes! i guess it would almost be an intro to programming since we have to find the developers mistakes? NOT BASHING the dev, because the good lord knows i would not be able to make this and i will always give credit where credit is due…But i thought they had a group of people to go in and test this stuff. I actually suggested a system where you can go into a topic called “intstruction/excersise propblem” and the pinned post will tell them to look through first and see if anyone else has that problem , upvote them, and if a problem gets enough upvotes a bot sends the report to either a dev or admin for review to be sent to the dev for a fix. We will see if they take the advice, it would probably make bug reports so much easier/more organized…right?
Programming can be very overwhelming, as we all know. These mistakes can make ya throw a laptop against the wall BUT we will eventually do this stuff and wanna throw our laptops against the wall. Since we would work for a company and have to read someone elses code with (more than likely) less context than there is here. It’s good preperation and kind of weeds out the ones not fully serious. Side note, i remember watching that when i was younger. The intro freaked me out so I made it a point to watch it xD

It looks like a couple of the inconsistencies have been resolved except “-1” still appears at the end of the instructions for #12. When this happens do we need to use the “report a bug” function to bring the issue to someone’s attention or do items like this automatically get surfaced from the community discussion?

Not automatic, as far as I know. Someone on that side needs to monitor the activity on the forums and act upon issues that surface. As I understand, CC is currently working up a new protocol to be sure these topics get looped in to update cycles. Should be hearing something to this effect in the next couple of months.

1 Like