function - recursion

def test1():
  num = int(input('please enter a number'))
  if num % 2 == 0: #Determine whether the input number is even
    reture True #If it is even, the program exits and returns true
  print('If it is not even, please re-enter')
  return test1() #If it is not even, continue to call yourself and enter the value

print(test1()) #call test1

Recursion: a function calls itself

Disadvantages:
  1. The recursion is the most recursive 999 times.
  2. The efficiency of recursion is not high

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325207826&siteId=291194637