以下是声明:
def recursive(y):
if y < 10:
return y
else:
z = raw_input("Please enter a number: ")
recursive(z)
x = raw_input("Please enter a number: ")
t = recursive(x)
print t
每当我运行它时,如果我输入一个等于或大于10的数字,它会提示我再次输入一个数字。如果我输入一个小于10的数字,它仍然告诉我输入一个数字;但是,如果我输入少于10,if y < 10
不应该是真的,它会返回那个数字吗?
答案 0 :(得分:0)
你有两个问题:
以下是更正后的版本:
def recursive(y):
if y < 10:
return y
else:
z = raw_input("Please enter a number: ")
return recursive(int(z))
答案 1 :(得分:-1)
一如既往,因为你没有在你的分支中返回......
def recursive(y):
if float(y) < 10: # also you need to make this a number
return y
else:
z = raw_input("Please enter a number: ")
return recursive(z) #this is almost always the problem with these questions