Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHARMANDEEP PANNU
2,077 Pointscode not working line 12, in showLetters for x in grades: TypeError: 'float' object is not iterable
def main():
scores = input("Enter five test scores: ")
scores = [int(x) for x in scores.split(",")]
showLetters(scores)
calc_average(scores)
def showLetters(grades):
for x in grades:
scores = [int(x)]
if x >= 90 and x <= 100:
grades = "A"
elif x >= 80 and x <= 89:
grades = "B"
elif x >= 70 and x <= 79:
grades = "C"
elif x >= 60 and x <= 69:
grades = "D"
elif x < 60:
grades = "F"
print("{:.1f} is {}".format(x, grades))
def calc_average(grades):
total = 0
for el in grades:
scores = [int(el)]
total += el
average = total / 5
letter = showLetters(average)
print("The average is: {:.1f} which is {}".format(average, letter))
main()
HARMANDEEP PANNU
2,077 Pointsline 12, in showLetters
for x in grades:
TypeError: 'float' object is not iterable
This is the error I'm getting.
1 Answer
Steven Parker
231,236 PointsThe wrong argument type is being passed to showLetters().
The function showLetters() takes an iterable argument (such as a list) and prints messages but does not return any value.
But in calc_average() it is being called on this line:
letter = showLetters(average)
The variable average contains a float value at this point, which causes the error. But also notice that letter is being assigned here and will always be None, since showLetters() does not return anything.
Tatiana Perry
17,156 PointsTatiana Perry
17,156 PointsCan you paste this as a code block. Use the markdown cheat sheet if you need help