如果使用for循环,如何保存用户的多个输入?

时间:2012-10-02 18:20:50

标签: python-3.x

for i in n:
    sn = str(input("What is the student's name? "))
    sg = eval(input("What is the student's grade? "))

如果您执行此类操作,那么您将如何保留用户的输入并将其存储?

1 个答案:

答案 0 :(得分:0)

您可以使用数组:

names = []
grades = []
for i in n:
    sn = str(input("What is the student's name? "))
    names.append(sn)
    sg = eval(input("What is the student's grade? "))
    grades.append(sg)