79461358

Date: 2025-02-23 14:09:17
Score: 0.5
Natty:
Report link

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")
Reasons:
  • Whitelisted phrase (-1): Hope this helps
  • Long answer (-0.5):
  • No code block (0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Sahil Patel