Python - Trying to check if a input is convertible to float, on second pass I get NoneType

Viewed 10

So I'm trying to learn python, don't have any background on programming picked up a simple calculator project, in it I don't want the program to crash everytime the user inputs something other than a number so I pass the input through a try/except. Thing is, if the user inputs a letter on the first "loop", on the second I get a "NoneType" kind of data, here's my code for the try/except:

def user_num():
    num = input(">>>")
   
    try:
        int(num)
        return num
    except:
        print("I need a number.")
        user_num()
print("First number:")
x1 = user_num()
0 Answers
Related