# Need help with the Carly's Clippers project

#1

Hello

I’m struggling to get this project going, currently stuck at the point 8:

• Use a for loop to create a variable `i` that goes from `0` to `len(hairstyles)-1` (you can use `range()` to do this!)

English being not my main language, I’m not sure how to proceed. I already defined the total_revenue = 0 variable the prior step required but I don’t know how to continue

#2

How would one construct a loop over a list’s indexes, given length? The hint above suggests using `range()`. Try a couple practice loops in the console using `print` to see instant results.

#3

I wrote this

for i in hairstyles:
i = range(0, (len(hairstyles) -1))
print(i)

And this is what I get

range(0, 7)
range(0, 7)
range(0, 7)
range(0, 7)
range(0, 7)
range(0, 7)
range(0, 7)
range(0, 7)

My issue is that I cannot seem to understand what the excersise is asking me to do, in logical terms

Next step indicates:

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.

This one is even more confusing

#4

``````for i in range(len(hairstyles)):
``````

Recall that the last (highest) value is not included in the range. This is useful when it comes to lists. `range` defaults to zero as the starting value if not specified.

Within that loop you will access (look up) index `i` in two separate lists. Their product will go into the prices list, at index `i`.

``list1[i] * list2[i]``

#5

Well, this is helpful but still I cannot get my head around it, this is the first time i get mindblocked so hard

total_revenue = 0

for i in range(len(hairstyles)):
i = (0,(len(hairstyles) - 1))
total_revenue = list(prices[i]) * list(last_week[i])
print("Total Revenue: " + (total_revenue))

and I get this error

TypeError: list indices must be integers or slices, not tuple

I’m going to go over the whole loops chapter seems there is something I miss

#6

We cannot give a float or an integer to the list constructor.

``````>>> list(1)
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
list(1)
TypeError: 'int' object is not iterable
>>> list(3.14)
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
list(3.14)
TypeError: 'float' object is not iterable
>>>
``````
``````prices[i] * last_week[i]
``````

Recall that we are accumulating a total, not assigning it anew. That will give only the final value assigned.

``````a += b * c
``````

Sorry if this created confusion. Should have stuck to letters.

#7

After a while I got around it. Thank you!

#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.