[Solved] i want to generate an exception when user enters integer values instead of String value.. how can i do it?


Since you are interested in Type Checking, You may want to reverse your Logic a little bit like so:

def log_in():
    user_name1  = "xyz"
    user_name   = input("Enter your username:\n") # str()
    try:
        # FOR YOUR USE CASE, IT WOULD SUFFICE TO SIMPLY TRY TO CAST THE ENTERED 
        # INPUT TO AN INT (INITIALLY) -  REGARDLESS OF WHETHER IT'S INT OR STRING:
        # PERHAPS STRIP-OFF ALL EXTRA WHITE-SPACES AS WELL
        int( user_name.strip() )

        # IF WE ARE SURE IT'S AN INT, THEN: WE RESPOND ACCORDINGLY -
        print("Solely Numeric characters are not allowed as Username....")
        # THEN IMMEDIATELY BAIL OUT OF THE FUNCTION:
        return False
    except:
        pass

    # COMPARE ENTERED USERNAME WITH EXPECTED VALUE
    # IF ALL GOES WELL THEN, WELCOME THE USER
    if user_name.strip() == user_name1:
        print("welcome")
    else:
        print("Wrong Credentials....")

log_in() 

enter image description here

0

solved i want to generate an exception when user enters integer values instead of String value.. how can i do it?