lundi 8 juin 2020

Validation- prompting user again for input if input is wrong

while exit :
    serialnumber = int(input("serial number of product :"))
    try:
        if len(str(serialnumber)) == 6:
            break
        else :
            print("serial number cant be used")

        serialnumber = int(serialnumber)
        break
    except ValueError :
        print("Invalid input")
        print()

hi guys i have been trying to perform validation on my input so i am trying to make sure that the input does not go over 6 characters. i would also like my program to ask for the input until its correct, however from what i tried ^ above codes, if my input is wrong the if else statement will just display serial number cant be used and it wont prompt the user again.

i will appreciate any help i can get thanks alot in advance

Aucun commentaire:

Enregistrer un commentaire