Python 当循环输出无正确错误时

Python 当循环输出无正确错误时,python,python-2.7,Python,Python 2.7,我正在尝试创建一个python程序,该程序将询问学生的姓名和分数,但我需要验证这些分数,假设考试是20分,所以分数不应该小于零或大于20,所以我使用while循环来完成此操作,但当我运行它时,每个分数都会给出一个错误。这是我的代码 Student_Name = [str] Test1 = [int] for i in range(3): Student_Name = raw_input("please input the name of Student {}: ".format(i+1)) T

我正在尝试创建一个python程序,该程序将询问学生的姓名和分数,但我需要验证这些分数,假设考试是20分,所以分数不应该小于零或大于20,所以我使用while循环来完成此操作,但当我运行它时,每个分数都会给出一个错误。这是我的代码

Student_Name = [str]
Test1 = [int]

for i in range(3):
Student_Name = raw_input("please input the name of Student {}: ".format(i+1))
Test1 = raw_input("please input the mark for Test1 of {}: ".format(Student_Name))
while Test1 > 20 or Test1 <0:
    print "invalid"
    Test1 = raw_input("please Reinput mark of {}: ".format(Student_Name))
Student_Name=[str]
Test1=[int]
对于范围(3)中的i:
学生姓名=原始输入(“请输入学生姓名:”.format(i+1))
Test1=原始输入(“请输入{}:”.format(学生名称))的Test1标记)

当Test1>20或Test1时,所提供的代码存在许多问题。首先,关闭for循环的缩进。其次,您对名为
Student\u Name1
Test1
的列表以及名为
Student\u Name1
Test1
的输入变量使用了相同的名称。第三,Python中的
raw\u input
返回一个
str
,您需要将其转换为
int

student_names = [str]
tests = [int]

for i in range(3):
    student_name = raw_input("please input the name of Student {}: ".format(i+1))
    test_score = int(raw_input("please input the mark for Test1 of {}: ".format(student_name)))
        while test_score > 20 or test_score < 0:
        print "invalid"
        test_score = int(raw_input("please Reinput mark of {}: ".format(student_name)))
student_name=[str]
测试=[int]
对于范围(3)中的i:
学生姓名=原始输入(“请输入学生姓名:”.format(i+1))
test_score=int(原始输入(“请输入{}:”.format(student_name))的Test1的分数)
当测试分数>20或测试分数<0时:
打印“无效”
测试分数=int(原始输入(“请重新输入{}:”.format(学生姓名))的分数)
这段代码应该提供您正在寻找的内容,或者至少是一个很好的参考