Carly's Clipper Challenge - Loops

In questions 2 and 3 in Carly’s Clipper Challenge in the Python 3 course, I wrote out a code to iterate through a price list and add each price to a new variable. This new variable is then used along with the length of the price list to get the average price.
Link to the code is here:

I created the below code:

prices = [30, 25, 40, 20, 20, 35, 50, 35]

for price in prices:
  average_price = total_price/len(prices)

Which resulted in each price in the list generating an average price vs. only one average price for the entire list. Why is this? I watched the GetHelp video and my code matches exactly what the developer writes out in his code, but he only gets one average price.

This is what my print out of average_price yields:
Average Haircut Price:$3.75
Average Haircut Price:$6.875
Average Haircut Price:$11.875
Average Haircut Price:$14.375
Average Haircut Price:$16.875
Average Haircut Price:$21.25
Average Haircut Price:$27.5
Average Haircut Price:$31.875

Lines 12 and 14 should not be indented.


2 posts were split to a new topic: Why subtract 1 from range?