Generation

generate functionSat, 17 Jun 2023

Write a program that receives an integer n that represents the height of a tree. Each level of the tree has 2^n identical elements that represent the n-level in which the value is found. Each floor is connected by slash type characters (That is, \ and /) which increase in quantity from 2^0 to 2^n on the lowest floor. The main goal is to perform the task WITHOUT the help of iterative control structures (While, For, Do While). Example: input: 3 output: 3 3 3 3 3 3 3 3 \ / \ / \ / \ / 2 2 2 2 \ / \ / \ / \ / 1 1 \ / \ / \ / \ / 0

def Tree(n): if n == 0: print(0) else: for i in range(n): print(' '*(n-i-1) + (str(i) + ' ')*(2**i) + ' '*(n-i-1)) print(' '*(n-i-2) + ('\\/'*(2**i)) + ' '*(n-i-2)) Tree(3)

Questions about programming?Chat with your personal AI assistant