# Printing powers of base # from j=0 oto j=n def powers(base, n): for i in range(n): print(base**i, end=" ") print() powers(3, 10) # Prints divisors of n def divisors(n): # The cycle runs to n+1, since n also divides itself! for i in range(1, n + 1): if n % i == 0: print(i, end=" ") print() divisors(14) # Printing subsequence # 1 1 2 1 2 3 1 2 3 4... def subsequences(n): count = 0 sub = 1 # Number of the subsequence while count < n: for i in range(sub): # Prints subsequence print(i + 1, end=" ") count += 1 if count == n: # We jump out of cycle if we reach desired length os sequence break sub += 1 print() subsequences(8) # Function returns length of the integer number x # It tells us how many times we need to divide the number # to reach zero def num_length(x): l = 0 while x > 0: x = x // 10 l += 1 return l print(num_length(4076)) # Prints the table of products def table_products(n): # First line print(" ", end="") for i in range(1, n + 1): print(i, end=" ") print() # Second line print(" ", end="") for i in range(1, n + 1): print("-", end=" ") print() # Table for row in range(1, n + 1): print(row, end=" | ") for col in range(1, n + 1): print(row * col, end=" ") print() table_products(15) # Prints empty square def empty_square(n): # First line for i in range(n): print("#", end=" ") print() # The middle for i in range(n - 2): print("#", end=" ") for j in range(n - 2): print(".", end=" ") print("#") # Last line for i in range(n): print("#", end=" ") print() empty_square(30) # Prints pyramid def pyramid(n): width = 2*n - 1 # The width of the pyramid base for r in range(n): nr = 2*r + 1 # The width of the pyramid in row r empty = (width - nr) // 2 # The number of epty spaces for j in range(empty): print(".", end=" ") for j in range(nr): print("#", end=" ") for j in range(empty): print(".", end=" ") print() pyramid(4)