Why does it run into issues when running my code?

Question

Why does it run into issues when running my code?

Answer

The most common issue is forgetting to make a list of your students called students! The first step is to create that list, then you can print the values asked for by using the awesome functions you’ve created throughout this project.

1 Like

Where did the grades bit I typed go? It’s now missing.

1 Like

Could you be a bit more specific? We have no access at all to your workspace.

Sure. In the ‘Student becomes the teacher’ part of the Python (not 3, I think it’s 2.7) course there’s an exercise called ‘Weight and see”. By then you collect this section of code and by the last exercise (which links to this forum page) the following code disappears but you need it to complete:

def get_letter_grade(score):
if score >= 90:
return “A”
elif score >=80:
return “B”
elif score >=70:
return “C”
elif score >=60:
return “D”
else:
return “F”

2 Likes

I had the same issue, it appears to be a bug in the exercise. Once I pasted it back in and then followed the instruction, it worked.

1 Like

I had a different issue in this exercise. I passed the exercise without really finishing it first! There was that last step which asked to print the letter grade and when I pressed enter to get on a new line in the code editor to write that piece of code, I just received the notification that I passed the test! I think it’s a bug. I swear, I will finish the code now to pass it properly. I don’t like to feel like a cheater!

God I didn’t notice that… Haha I’m laughing out loud right now XD…

guys I have a question, at the last part,
when i wrote:

def get_class_average(class_list):
results =
for student in class_list:
student_avg = get_average(student)
results.append(student_avg)
return average(results)

students = [lloyd, alice, tyler]

avg = get_class_average(students)
print(avg)
print(get_letter_grade(avg))

it prints an average of 91.2 and A
but the same code from solutions prints out a 83.4 or something and B

I can’t spot the difference here
any help would be welcome

ps the code in solutions is:

def get_class_average(class_list):

results =

for student in class_list:

student_avg = get_average(student)

results.append(student_avg)

return average(results)

students = [lloyd, alice, tyler]

avg = get_class_average(students)

print(avg)

print(get_letter_grade(avg))

1 Like

Thanks for the answer but I still don’t spot the difference.
This is the code which will display an A as a result, which might be wrong, but I still can pass and finish the module. Btw, the result it is still 83.86....

lloyd = {
  "name": "Lloyd",
  "homework": [90.0, 97.0, 75.0, 92.0],
  "quizzes": [88.0, 40.0, 94.0],
  "tests": [75.0, 90.0]
}
alice = {
  "name": "Alice",
  "homework": [100.0, 92.0, 98.0, 100.0],
  "quizzes": [82.0, 83.0, 91.0],
  "tests": [89.0, 97.0]
}
tyler = {
  "name": "Tyler",
  "homework": [0.0, 87.0, 75.0, 22.0],
  "quizzes": [0.0, 75.0, 78.0],
  "tests": [100.0, 100.0]
}


def average(numbers):
  total = sum(numbers)
  total = float(total)
  return total / len(numbers)

def get_average(student):
  homework = average(student["homework"])
  quizzes = average(student["quizzes"])
  tests = average(student["tests"])
  return homework * 0.1 + quizzes * 0.3 + tests * 0.6

def get_letter_grade(score):
  if score >= 90:
    return "A"
  elif score >= 80:
    return "B"
  elif score >= 70:
    return "C"
  elif score >= 60:
    return "D"
  else:
    return "F"

print get_letter_grade(get_average(lloyd))

def get_class_average(class_list):
  results = []
  for student in class_list:
    results.append(get_average(student))
  return average(results)

students = [alice, lloyd, tyler]
print get_class_average(students)

# I always have to print the function and not what is inside! 

print get_letter_grade(get_class_average)

So that would make me display the following result.
image

If I change the last line of code to print get_letter_grade(get_class_average(students)) I would get the logical answer. I don’t know why this first output.

Here’s the result if I modify the line of the code (which I understand why).
image

Thanks in advance and have a great day.

1 Like