python - creating a code that use .isdigit -


i'm new python. creating code use .isdigit. goes this:

a = int(input("enter 1st number: "))  if 'a'.isdigit():      b = int(input("enter 2nd number: "))  else:      print "your input invalid." 

but when enter alphabet, doesn't come out "your input invalid. , if entered digit, doesn't show b, 'enter 2nd number'.

is there anyway out there can me see what's issue code. great help. thanks.

you assigning input variable a, when try query isdigit() you're querying string 'a', not variable created.

also, forcing conversion int before you've checked if it's int. if need convert int, should after run .isdigit() check:

    = raw_input("enter 1st number: ")  if a.isdigit():      = int(a)     b = int(raw_input("enter 2nd number: "))  else:      print("your input invalid.") 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -