如果给定的数字小于2,它将要求使用递归重新输入该数字。
我先给出2,然后递归后给出3,但是输出仍然是2。
如何输出3?
def inexpno():
exp = int(input("Enter the Experiment n.o : ")) # Takes a exp number
if exp<=2: # Enter your completed experiment here
print("It is completed Correction for both Record and Observation\n\n")
print("Do you want to select another experiment")
we = input("")
if we == "yes" or we == "YES":
inexpno() # TO CHANGE
else:
exit()
return exp
print(inexpno())
答案 0 :(得分:1)
当前,您没有在第8行的递归调用中保存来自inexpno()
的返回值。您只需要将其保存为exp
:
exp = inexpno()
答案 1 :(得分:1)
只需将递归行更改为
return inexpno()