Avatar of crazy4s
crazy4s

asked on 

How can i check whether the input is a number or string

Hi all,
I was trying out to write a small prog to prompt the user input for numbers...
I used the isdigit func to check whether the input is a number or string... it works but this doesn't accept float as a number... how can i do to make it works for both integer and float?

while True:    
    n1 = input("Enter the first number: ")
    if n1.isdigit() == False:
        print("Invalid input!")
    else:
        n1 = int(n1)
        break
Python

Avatar of undefined
Last Comment
crazy4s

8/22/2022 - Mon