-3

I am new to python and I need to write a recursive python program but I need some guidance on how to get started. I have never come across a problem like this so any help would be greatly appreciated.

The recursive function that will print all the integers between n and 1 in descending order. Pass the value n = 4 to the function.

def function(n):
    if n>0 or n==1:
        Return 4
Victoria
  • 17
  • 1
  • 6
  • 1
    Maybe you should reread the chapter of the textbook on recursion. You're not going to learn anything by just copying code from an answer. – Barmar Nov 24 '16 at 03:49
  • 1
    It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (output, tracebacks, etc.). The more detail you provide, the more answers you are likely to receive. Check the [FAQ](http://stackoverflow.com/tour) and [How to Ask](http://stackoverflow.com/questions/how-to-ask). – TigerhawkT3 Nov 24 '16 at 03:52
  • Regarding the duplicate: note the bullet point in the top answer, "For printing in ascending order, the `print` statement must be placed _after_ the recursive call." – TigerhawkT3 Nov 24 '16 at 03:56

2 Answers2

0

Your answer should look something like this. The function has to be called within itself for it to be recursive. Therefore, while it meets a certain condition, a recursive function, as given below, should call itself.

def function(n):
    if n>0:
        print(n)
        function(n-1)
Ashan
  • 317
  • 1
  • 10
-1

a recursive function calls itself so something like:

def descending(n):
    if(n > 0):
        print(n)
        descending(n-1)
h3adache
  • 1,296
  • 11
  • 18