You could replace the for loop by this What this does is it just breaks the inner for loop for the invalid input and not the entire for loop. The while loop only runs for a single element of the list.
This type of problem could have been more easily solved if it were c++ as we could just decrement x by one in else block. Hope this helps!
for x in range(0,len(students)): while True: register=input(f"Is {students[x]} present? ") if register == "yes": present += 1 break elif register == "no": absent += 1 break else: print("invalid input")