Last active
December 5, 2016 22:20
-
-
Save s2t2/2c45e33340fab5feac29568c95f040a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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