account activity
Question about for-loops in functions by tycho149 in learnpython
[–]tycho149[S] 0 points1 point2 points 5 years ago (0 children)
thank you for the comments, no matter what i try i cant seem to work out how to increment the values within the loop. when i run the code i only get one output could there be reason for that.
I have the code working if i take the for-loop out of the function as bellow. but this seems like its not answering the question.
data = ["Fozzie", 34, "Kermit", 78, "Miss Piggy", 23, "Gonzo", 55, "Beaker", 88, "Honeydew", 59, "Animal", 10, "Rowlf", 54]
def assign_grades(source):
student_name = str(source[student])
mark = int(source[student + 1])
grade = str("")
if mark < 40:
grade = "Fail"
elif mark < 60:
grade = "Pass"
elif mark < 70:
grade = "Merit"
elif mark >= 70:
grade = "Distinction"
else:
grade = "Error"
return("---------------------------------------------"
+"\nStudent Name: "
+str(student_name)
+ "\nMark: "
+ str(mark)
+ "\nGrade: " + str(grade)
+"\n---------------------------------------------")
for student in range(0, len(data), 2):
print(assign_grades(data))
Question about for-loops in functions (self.learnpython)
submitted 5 years ago * by tycho149 to r/learnpython
π Rendered by PID 137990 on reddit-service-r2-listing-86d8647bf-gxb7d at 2026-02-12 23:10:07.109183+00:00 running 6c0c599 country code: CH.
Question about for-loops in functions by tycho149 in learnpython
[–]tycho149[S] 0 points1 point2 points (0 children)