create a program that has a dictionary:
studentgrade={
"john" :90,
"doe" :70,
"jane":83,
"marie":67,
"robert":59,
}
change the value into its equivalent:
91-100-oustanding
81-90-verygood
71-80-good
61-70-poor
51-60-failed
sample output:
{'john' : 'verygood', 'doe':'poor','jane':'verygood','marie':'poor',
'robert':'failed'}
studentgrade={
"john" :90,
"doe" :70,
"jane":83,
"marie":67,
"robert":59,
}
for key, value in studentgrade.items():
# do something with value
if studentgrade[key]>=91 and studentgrade[key]<=100:
studentgrade[key]="oustanding"
elif studentgrade[key]>=81 and studentgrade[key]<=90:
studentgrade[key]="verygood"
elif studentgrade[key]>=71 and studentgrade[key]<=80:
studentgrade[key]="good"
elif studentgrade[key]>=61 and studentgrade[key]<=70:
studentgrade[key]="poor"
elif studentgrade[key]>=51 and studentgrade[key]<=60:
studentgrade[key]="failed"
print(studentgrade)
Comments
Leave a comment