Unable to understand why and is not working

I am trying to understand why Python is not getting into the loop and exiting with an error code. On the same time OR condition works fine.

def user_choice():

choice=''
within_range = False

while choice.isdigit == False and within_range == False:
    choice=input('Enter valid selection (1-9): ')
    
    if choice.isdigit() == False:
        print('You entered non-digit value, please input digit')
        
    if choice.isdigit() == True:
        if int(choice) in range(0,10):
            within_range=True
        else:
            within_range=False
    
return int(choice)


Read more here: https://stackoverflow.com/questions/64399792/unable-to-understand-why-and-is-not-working

Content Attribution

This content was originally published by Manish Amin at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: