Students = {}
def IslemYap():
Input = int(input("Process Number: "))
if Input == 1:
StudentName = input("Student Name: ")
for i in range(1,8):
Students.update({StudentName:[input()]})
print(Students)
IslemYap()
我正在尝试,但是不起作用。每个学生7次附加成绩。
您可以将成绩添加到列表中,只需将其添加到词典中的对应学生中
Students = {}
def IslemYap():
Input = int(input("Process Number: "))
grades = []
if Input == 1:
StudentName = input("Student Name: ")
for i in range(1,8):
grades.append(input())
Students.update({StudentName: grades})
grades = []
print(Students)
IslemYap()
您总是覆盖它,并且永远不会在适当的列表中填写成绩。
Students = {}
def IslemYap():
Input = int(input("Process Number: "))
if Input == 1:
StudentName = input("Student Name: ")
for i in range(1,8):
Students[StudentName] = Students.get(StudentName,[]) + [input()]
print(Students)
IslemYap()