-1

I'm new to programming world, and I'm struggling with recursion.

This is my code, but I'm not sure why it doesn't work :(

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))

thank you

3
  • what about the cases for x == 2 and x == 3? Commented Jun 1, 2015 at 4:37
  • Have a look: stackoverflow.com/questions/30565674/… Commented Jun 1, 2015 at 4:40
  • You're not handling 2 and 3 in your end cases. Also, if you are new to programming, I'd recommend you stay out of recursion for a while till you're comfortable with the basics. Commented Jun 1, 2015 at 4:43

1 Answer 1

1

Your g function doesn't handle inputs 2 and 3.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.