Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Il PRIMO numero da stampare è vIniz.
- # ~ OGNI ALTRO numero da stampare è uguale a "il doppio dell’ultimo numero stampato e successivamente diminuito di
- # uno".
- def progression(vIniz, h):
- progression_list = [ vIniz ]
- h = h // 2 + 1
- amount = (h * (h + 1)) - 1
- for i in range(1, amount):
- next_num = 2*progression_list[i - 1] - 1
- progression_list.append(next_num)
- return progression_list
- def get_graph(progression):
- res = []
- k = len(progression) - 1
- i = 1
- while(i < k):
- res.append(progression[:i])
- k -= i
- i += 1
- return res
- # print(progression(1, 5))
- # print(len(progression(1, 5)))
- vIniz = int(input("V iniz: "))
- h = int(input("h: "))
- top_part = get_graph(progression(vIniz, h))[::-1]
- bottom_part = get_graph(progression(vIniz, h))[1:]
- def print_row (row):
- for x in row:
- print(x, end="")
- print(top_part)
- def print_result(top_part, bottom_part):
- for x in top_part:
- print_row(x)
- print("")
- for x in bottom_part:
- print_row(x)
- print("")
- print_result(top_part, bottom_part)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement