递归(python)请帮忙

时间:2015-06-01 04:35:31

标签: python recursion

我是编程世界的新手,我正在努力进行递归。

这是我的代码,但我不确定为什么它不起作用:(

enter_number = input("enter 'x' value: ")
def g(x):
    if x == 0:
        return 1
    elif x == 1:
        return 2
    else:
        return g(x−1) + g(x−3) + g(x−4)

print(g(enter_number))

谢谢

1 个答案:

答案 0 :(得分:1)

您的2函数无法处理输入3def User(models.Model): ... is_teacher = models.BooleanField(default=False) ... def Section(models.Model): ... teachers = models.ManyToManyField(User, related_name="teachers") students = models.ManyToManyField(User, related_name="students") is_active = models.BooleanField(default=True) ...