I have the code which populates the list "oneStudent" with 5 values, I need to validate indexes 1-4 (so the last 4 values) as an integer. I have tried using try...except, however, no matter how I try to implement it, it breaks the code
I'm relatively new to coding and python, it's probably something small I'm missing, any help will be much appreciated
The idea behind the code is to populate the list oneStudent as many times as NumberOfStduent is input above, after each time the oneStudent list will be appended to allStudent and reset for the next one
in the end, allStudent will be a list containing lists with each oneStudent
while True:
NumberOfStudent = input ("Please input the number of students: ")
try:
NumberOfStudent=int(NumberOfStudent)
if NumberOfStudent in range (1, 6):
break
else:
print("Error, Please input between 1 and 5")
except:
print("Error, Please input a valid number")
print("Number of students:", NumberOfStudent)
allStudents=[]
oneStudent=[]
s=0
while s < NumberOfStudent:
oneStudent.append(input ("Please input student name: ", ))
oneStudent.append(input ("Please mark for the Web module: ", ))
try:
oneStudent[1]=int(oneStudent[1])
if oneStudent[1] > 0 and oneStudent[1] < 101:
pass
else:
print("error1")
except:
print("Error2")
oneStudent.append(input ("Please mark for the Programming module: ", ))
try:
oneStudent[2]=int(oneStudent[1])
if oneStudent[2] > 0 and oneStudent[2] < 101:
pass
else:
print("error1")
except:
print("Error2")
oneStudent.append(input ("Please mark for the Graphics module: ", ))
try:
oneStudent[3]=int(oneStudent[1])
if oneStudent[3] > 0 and oneStudent[3] < 101:
pass
else:
print("error1")
except:
print("Error2")
oneStudent.append(input("Please mark for the Networking module: ", ))
try:
oneStudent[4]=int(oneStudent[1])
if oneStudent[4] > 0 and oneStudent[4] < 101:
pass
else:
print("error1")
except:
print("Error2")
s = s+1
allStudents.append(oneStudent)
oneStudent=[]
if s == NumberOfStudent:
break
print(allStudents)