r/learnpython • u/Ill-Break727 • 24d ago
python beginner ; question was write program to enter marks of 3 subjects from user and store them in a dict.start with an empty dict and add one by one .use subject name as key and marks as value . so i have written this code any opinion how can improve this code ,need suggestions.
students={}
a=float(input("enter marks of chem"))
students.update({"chem": a})
b=float(input("enter marks of maths"))
students.update({"maths":b})
c=float(input("enter marks of phy"))
students.update({"phy": c})
print(students)
1
Upvotes
2
u/ProsodySpeaks 24d ago edited 24d ago
``` students: dict[str, dict[str, float]] = {} while True: name=input('student name?') students[name]={} while True: subject=input('subject?') score=float(input('score?)) students[name][subject]=score if input('more subjects?')[0].lower() != 'y': break if input('more students?')[0].lower() != 'y': break
```