2017-02-02 12 views
0

私は、学生の名前と成績を求めるPythonプログラムを作成しようとしていますが、テストが20歳を超えていると仮定してこれらのマークを検証する必要があります。 20以上より、ゼロまたはおろしので、私はそうするようにwhileループを使用していますが、私はそれを実行すると、すべてのマークはここでエラーを与えることは、私のコードは付属のコードを持つ多くの問題があります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)) 

答えて

1

です。最初に、インデントはforループのためにオフになっています。次に、Student_Name1Test1という名前のリストとStudent_Name1Test1という入力変数の両方に同じ名前を使用しました。第3に、Pythonのraw_inputstrを返します。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))) 

このコードは、探しているもの、または少なくとも参考になるものを提供します。

関連する問題