Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I typed is digit function for user input, but when I enter an alphabet, it accepts the value


            IDcheck = input("Enter The Customer ID ")
            if IDcheck.isdigit :
                print("Your ID is Being Searched")

            elif IDcheck.isalpha :
                print("IDs Only Contains Numbers")

I made a code to search customers names by ID . typed isdigit function to make sure the user enters a number
but when I type a letter, it does accept it. why

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

String.isdigit is a function.

When the interpreter executes the line if IDcheck.isdigit: it checks if a function or variable called IDcheck.isdigit exists. IDcheck.isdigit exist and it returns True. The same applies to IDcheck.isalpha.

To fix this: change IDcheck.isdigit and IDcheck.isalpha to IDcheck.isdigit() and IDcheck.isalpha() by adding parentheses, as in:

IDcheck = input("Enter The Customer ID ")
if IDcheck.isdigit():
    print("Your ID is Being Searched")

elif IDcheck.isalpha():
    print("IDs Only Contains Numbers")

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading