2017-02-02 34 views
0

我想創建一個蟒蛇程序,要求學生的姓名和成績,但我需要驗證這些標誌,假設考試不滿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的輸入變量使用了相同的名稱。第三,在Python中的raw_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))) 

此代碼應該提供您正在尋找的內容,或者至少是一個很好的參考。