📚 › Python: the friendliest first language
14. Mini project: a grade calculator
इस लेख का अनुवाद अपने आप होगा। अभी अंग्रेज़ी में दिखाया जा रहा है।
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.
उदाहरण देखें
def grade(m):
if m >= 80:
return "A"
elif m >= 50:
return "B"
return "C"
for m in [85, 60]:
print(grade(m))
✍️ अब आपकी बारी
Write grade(m) that returns A for 80 or more, B for 50 or more, otherwise C. Print grade(72).