while True: # Use a "while|true|break to ensure input is correct
try:
students = int(input('Enter number of students: ')) # I fnot an int, raise error
break # Stops while loop
except: # Catch not an int error
print("Input 'students ' must be an integer") # Print explanation, go to next while
counter = 0
lowest_score = None # None versus high number to avoid limits
lowest_name = None
second_lowest_score = None
second_lowest_name = None
testlist = [] # Just for checking alidity of order. Delete before submission
while (counter < students):
while True: # Get new input
try:
score = int(input('Please enter student {} score:'.format(counter)))
break
except:
print("Score must be an integer...")
name = input('Please enter student name:'.format(counter))
testlist.append(score) # Just for checking, Delete
# Handle first loop
if lowest_score is None:
lowest_score = score
lowest_name = name
continue
# Handle first loop
if second_lowest_score is None:
if score > lowest_score:
second_lowest_score = score
second_lowest_name = name
else:
second_lowest_score = lowest_score
second_lowest_name = lowest_name
lowest_score = score
lowest_name = name
continue # next iteration of main while
if (score < second_lowest_score) :
if (score >= lowest_score) :
second_lowest_score = score
second_lowest_name = name
else:
second_lowest_score = lowest_score
second_lowest_name = lowest_name
if score < lowest_score:
lowest_score = score
lowest_name = name
counter = counter + 1
print('2nd lowest student is ',
name,
'with score',
second_lowest_score)
print(sorted(testlist))