Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursion
#2
The problem is that you are subtracting num from num on line 17, so your look only runs once, not num times. Although if you want a loop to run a certain number of times you should use a for loop:

def show_ast(n):
    if n > 0:
        show_ast(n - 1)
    text = ''
    for ast in range(n):
        text += '*'
    print(text)
But with the multiplication of the string that you figured out, you don't need any loop:

def show_ast()
    if n > 0:
        show_ast(n - 1)
    print('*' * n)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Recursion - by koolinka - Dec-09-2018, 10:41 PM
RE: Recursion - by ichabod801 - Dec-09-2018, 11:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  GCF function w recursion and helper function(how do i fix this Recursion Error) hhydration 3 2,666 Oct-05-2020, 07:47 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020