0
How to write a function grade that takes in the name of the student and return the Grade of the student as a string?
How to write a function grade that takes in the name of the student and return the Grade of the student as a string? If a student attain 75 marks and above, he/she would attain a grade "A" If a student attain 60 marks and above, he/she would attain a grade "B" If a student attain 50 marks and above, he/she would attain a grade "C" If a student less than 50 marks , he/she would attain grade a "FAIL" scores = {"Patrick":77, "John" : 64, "Selina" : 59, "James":40 , "Louis": 88} https://code.sololearn.com/c7nxlFl7cvvx/?ref=app
2 Réponses
+ 3
heres how i would go about it
https://code.sololearn.com/cg2IXPCo25f3/?ref=app
0
Inside the function you'd have to write:
if scores[name] == ...
return 'A'
or whatever Delete that final return statement.
Then you call the function, for example like this:
for name in scores:
print(name, scores[name],
grade(name))
If you don't want your function to access the dictionary directly, I would change it to take only the score:
def grade(score):
if score ==...
Then call it by:
print(grade(scores[name])))
One more thing: In Python you can simplify your conditions:
if 60 < points < 75:
...