1

Here I need to get 10 IPv4 addresses and check them using a validator function if the IPv4 address is invalid it should again ask for that input alone which was invalid out of 10 from the user. If the IPv4 address is valid no problem it goes to the converter function and runs smoothly.

Here I tried this but this goes on an infinite loop

while True:
      ipv4 = input("Enter 10 IPv4 Address: ").split(" ")
      for i in range(10):
        if validator(ipv4[i]):
          converter(ipv4[i])
        else:
          print("Invalid IPv4 Address")
          while True:
            ip = input("Enter the Valid IPv4 Address:")
            if validator(ip):
              converter(ip)
              break
      break

1 Answer 1

0

make these changes in the second while loop:

while True:
    print(f"{ipv4[i]} is an Invalid IPv4 Address, add valid IPv4 Address")
    ipv4[i] = input("Enter the Valid IPv4 Address:")
    if validator(ipv4[i]):
        converter(ipv4[i])
        break

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.