Skip to content

Instantly share code, notes, and snippets.

@s2t2
Last active December 5, 2016 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s2t2/2c45e33340fab5feac29568c95f040a0 to your computer and use it in GitHub Desktop.
Save s2t2/2c45e33340fab5feac29568c95f040a0 to your computer and use it in GitHub Desktop.
#
# example using recursion, but output is reversed
#
def print_stars_desc(n):
print(str(n) + " stars: " + (n * "*"))
if n > 1:
print_stars_desc(n - 1)
print("")
print("---------------------------")
print_stars_desc(10)
# =>
# ('3 stars: ', '***')
# ('2 stars: ', '**')
# ('1 stars: ', '*')
##
## example does not use recursion, but output is correct
##
#def print_stars_asc(n):
# for i in range(1, n + 1):
# print(str(i) + " stars: " + (i * "*"))
#
#print("")
#print("---------------------------")
#print_stars_asc(3)
## =>
## ('1 stars: ', '*')
## ('2 stars: ', '**')
## ('3 stars: ', '***')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment