Advertisement
informaticage

sol 2

Feb 11th, 2021 (edited)
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #  Il PRIMO numero da stampare è vIniz.
  2. # ~ OGNI ALTRO numero da stampare è uguale a "il doppio dell’ultimo numero stampato e successivamente diminuito di
  3. # uno".
  4.  
  5. def progression(vIniz, h):
  6.   progression_list = [ vIniz ]
  7.   h = h // 2 + 1
  8.   amount = (h * (h + 1)) - 1
  9.   for i in range(1, amount):
  10.     next_num = 2*progression_list[i - 1] - 1
  11.     progression_list.append(next_num)
  12.  
  13.   return progression_list
  14.  
  15. def get_graph(progression):
  16.   res = []
  17.   k = len(progression) - 1
  18.   i = 1
  19.   while(i < k):
  20.     res.append(progression[:i])
  21.     k -= i
  22.     i += 1
  23.   return res
  24.  
  25. # print(progression(1, 5))
  26. # print(len(progression(1, 5)))
  27.  
  28. vIniz = int(input("V iniz: "))
  29. h = int(input("h: "))
  30. top_part = get_graph(progression(vIniz, h))[::-1]
  31. bottom_part = get_graph(progression(vIniz, h))[1:]
  32.  
  33. def print_row (row):
  34.   for x in row:
  35.     print(x, end="")
  36.  
  37. print(top_part)
  38. def print_result(top_part, bottom_part):
  39.   for x in top_part:
  40.     print_row(x)
  41.     print("")
  42.  
  43.   for x in bottom_part:
  44.     print_row(x)
  45.     print("")
  46.  
  47. print_result(top_part, bottom_part)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement