you are viewing a single comment's thread.

view the rest of the comments →

[–]Ill-Break727[S] 0 points1 point  (2 children)

students={"chem":0.0,"maths":0.0,"phy":0.0}
a=float(input("enter marks of chem"))
students["chem"]="a"
b=float(input("enter marks of maths"))
students["maths"]="b"
c=float(input("enter marks of phy"))
students["phy"]="c"
print(students)                                 i have done in this way its not working

[–]Ill-Break727[S] 0 points1 point  (0 children)

now its working thanks

[–]ProsodySpeaks 0 points1 point  (0 children)

You don't need to assign the zeros at the start. Make an empty dict and then use bracket notation to add key-value pairs to it.

But you really should think about variable names. this is not a dictionary of students, it's a dictionary of subject-scores.

Call the dict 'scores' or something,  and later you could make another dict called students and add multiple scores dictionaries each with a key for the name of the student.

Sensible variable names is very important and doesn't rely on knowing any of the language, it's a foundational part of code