Homepage Forums Dev & Debugging How to validate user input? Reply To: How to validate user input?

  • Vincent J. Gerner

    Member
    December 26, 2020 at 10:28 am
    321 Coins
    71 Gems
    Helpful
    Up
    0
    Down
    Not Helpful

    Using ValueError will be a much better way.

    try:
    empid=int(input("PLease enter employee ID "))
    except ValueError:
    print("Please enter a valid number ")
    if empid == 1100345002:
    print("Your entry has been registered.")
    else:
    print("Sorry the ID is not recognised.")

New Report

Close