📚 › Python: the friendliest first language
14. Mini project: a grade calculator
Este artículo se traducirá automáticamente. Por ahora se muestra en inglés.
Combine the ideas: a function takes a mark and returns a grade with if and elif. Then a loop prints the grade for each mark in a list.
This is the pattern behind most real programs: data in, rules applied, result out.
Ver ejemplo
def grade(m):
if m >= 80:
return "A"
elif m >= 50:
return "B"
return "C"
for m in [85, 60]:
print(grade(m))
✍️ Ahora te toca
Write grade(m) that returns A for 80 or more, B for 50 or more, otherwise C. Print grade(72).