-1

These line of codes are part my program. I'm trying to make a simple calculator.

def num1():
    x = input('Enter your first number: ')
    
    if x.isdigit():
        return int(x)
        
    else:
        num1()

My program works fine until this function call itself and it will return None even i entered an integer.

  • Also, instead of using recursion for this you should use iteration. You should remove the `else:` part and add `while True:` as the first line of the function indenting everything else inside that. – quamrana Aug 15 '22 at 15:21
  • @quamrana Thanks. My program works better. – Joseph Tiglao Aug 16 '22 at 14:01

1 Answers1

0

You want return num1() so the value obtained from the base case percolates back up to the initial call.

Addison Schmidt
  • 374
  • 1
  • 7