You are viewing a single comment's thread. Return to all comments →
My function in Python:
def staircase(n): for i in range(1, n+1): # starts in '1' until 'i' is equal to 'n+1' print(' '*(n-i)+"#"*i) ''' adds a number of spaces equal to 'n-i'. Let's say if the number of the input (n) is '5', on the first iteration, 'i' will have the '1' value, wich by the syntax (n-i), it will print '4' spaces in total (' '*4). The same logic is applied to '#', it will print '#' based on the value of 'i' and since it is a string, it will always concatenate to the end of the string. '''
Seems like cookies are disabled on this browser, please enable them to open this website
Staircase
You are viewing a single comment's thread. Return to all comments →
My function in Python: