59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
student_names = {}
|
|
|
|
# data structure
|
|
# student_names = {
|
|
# "john": {
|
|
# "HW1": 15
|
|
# "HW2": 20
|
|
# },
|
|
# "jane": {
|
|
# "HW1": 10
|
|
# "HW2": 15
|
|
# }
|
|
# }
|
|
|
|
def get_student_name():
|
|
while True:
|
|
student_name = input("Enter student name: ").strip().lower()
|
|
if student_name == "!break":
|
|
return None
|
|
elif student_name in student_names:
|
|
return student_name
|
|
else:
|
|
return student_name
|
|
|
|
def update_data(student_name, hw, score):
|
|
if student_name not in student_names:
|
|
student_names[student_name] = {}
|
|
|
|
if hw not in student_names[student_name]:
|
|
student_names[student_name][hw] = score
|
|
else:
|
|
print("HW already exists.")
|
|
|
|
def display_data():
|
|
for student in student_names:
|
|
print(f"{student}:")
|
|
for hw in student_names[student]:
|
|
print(f" {hw}: {student_names[student][hw]}")
|
|
|
|
def main():
|
|
Run = True
|
|
|
|
while Run:
|
|
student_name = get_student_name()
|
|
|
|
if student_name is None:
|
|
Run = False
|
|
print("Outputting data...")
|
|
break
|
|
|
|
hw = input("Enter homework name: ").strip().lower()
|
|
|
|
score = int(input("Enter score: "))
|
|
update_data(student_name, hw, score)
|
|
|
|
display_data()
|
|
|
|
if __name__ == "__main__":
|
|
main() |