Python; Review, 9/9 Infinite Loop Help!


#1

https://www.codecademy.com/courses/learn-python/lessons/exam-statistics/exercises/review-2?action=lesson_resume&link_content_target=interstitial_lesson

No error messages, the code is stuck in a loop, Once I press run, it never loads or allows me to advance forward



grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def print_grades(grades_input):
for grade in grades_input:
print grade

def grades_sum(scores):
total = 0
for score in scores:
total += score
return total

def grades_average(grades_input):
sum_of_grades = grades_sum(grades_input)
average = sum_of_grades / float(len(grades_input))
return average

print print_grades(grades)
print grades_sum(grades)
print grades_average(grades)
print grades_variance(scores)
print grades_std_deviation(variance)




#2

those are not defined, and you dont need to make len(grades_input) a float on a division
just to try something, change “total = 0” to “total = 0.0”

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def print_grades(grades_input):
for grade in grades_input:
print grade

def grades_sum(scores):
total = 0.0
for score in scores:
total += score
return total

def grades_average(grades_input):
sum_of_grades = grades_sum(grades_input)
average = sum_of_grades / (len(grades_input))
return average

print print_grades(grades)
print grades_sum(grades)
print grades_average(grades)
print grades_variance(scores)
print grades_std_deviation(variance)

this is the output i have
100
100
90
40
80
100
85
70
90
65
90
85
50.5
None
1045.5
80.42307692307692


#3

Made the changes suggested (thanks for seeing those) However , still running and not finishing though. I have reset the exercise and after getting the prompt that “the code has been moved” I have reset the code. Still no luck .


#4

Where is your indentation? Python relies upon indents to distinguish between code blocks and establish scope parameters.

For this exercise set aside concern for floats. The data contains a float so the program will assume that state by default.

As mentioned above, scores is not defined. Use grades for the argument in this function call.

This function should use the return value of the grades_variance function.

print grades_std_deviation(grades_variance(grades))

#5

image

Still getting this error message: See above.

Here is the updated code;

grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]

def print_grades(grades_input):
  for grade in grades_input:
print grade

def grades_sum(scores):
total = 0.0
  for score in scores:
total += score
    return total

def grades_average(grades_input):
sum_of_grades = grades_sum(grades_input)
average = sum_of_grades /(len(grades_input))
   return average

print print_grades(grades)
print grades_sum(grades)
print grades_average(grades)
print grades_variance(grades)
print grades_std_deviation(grades_variance(grades))

#6

Needs indent.

Likewise.

Again, likewise.

Fix the indentation, copy your code, go back to the previous lesson, Run and Next. If the code is present then check it for errors and complete it, else paste the code in and Run.


#7

Still unable to get this, the work environment keeps moving the code making it unable to run smoothly. I have tried going back until I don’t get the moved code error as well as resetting the code. I keep losing my code every time.


#8

Hi pcalhoun,

I had the same problem. I have test my code in eclipise environment and it worked. my solution was to copy my code on txt file then to reset the exercise and then going back to the start and re-entering the code for each section. I was able re-enter the solution and was able to get the solution to work. I had to do this twice to get it work.


#9

Finally got it to work. Tested my code in eclipse then went and reset until I no longer received the error message. Input code and was able to move forward! Thanks!


#10

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