SHARE
TWEET

Untitled

a guest Oct 21st, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """Program that creates beautiful pyramids."""
  2.  
  3.  
  4. def make_pyramid(base: int, char: str) -> list:
  5.     """
  6.     Construct a pyramid with given base.
  7.  
  8.     Pyramid should consist of given chars, all empty spaces in the pyramid list are ' '. Pyramid height depends on base length. Lowest floor consists of base-number chars.
  9.     Every floor has 2 chars less than the floor lower to it.
  10.     make_pyramid(3, "A") ->
  11.     [
  12.         [' ', 'A', ' '],
  13.         ['A', 'A', 'A']
  14.     ]
  15.     make_pyramid(6, 'a') ->
  16.     [
  17.         [' ', ' ', 'a', 'a', ' ', ' '],
  18.         [' ', 'a', 'a', 'a', 'a', ' '],
  19.         ['a', 'a', 'a', 'a', 'a', 'a']
  20.     ]
  21.     :param base: int
  22.     :param char: str
  23.     :return: list
  24.     """
  25.     table = []
  26.     b = 0
  27.     for _ in range(base):
  28.         while base > 0:
  29.             append_line = []
  30.             for _ in range(int(b / 2)):
  31.                 append_line += " "
  32.             for _ in range(base):
  33.                 append_line += char
  34.             for _ in range(int(b / 2)):
  35.                 append_line += " "
  36.             base -= 2
  37.             b += 2
  38.             table.append(append_line)
  39.     table.reverse()
  40.     return table
  41.  
  42.  
  43. def join_pyramids(pyramid_a: list, pyramid_b: list) -> list:
  44.     """
  45.     Join together two pyramid lists.
  46.  
  47.     Get 2 pyramid lists as inputs. Join them together horizontally. If the the pyramid heights are not equal, add empty lines on the top until they are equal.
  48.     join_pyramids(make_pyramid(3, "A"), make_pyramid(6, 'a')) ->
  49.     [
  50.         [' ', ' ', ' ', ' ', ' ', 'a', 'a', ' ', ' '],
  51.         [' ', 'A', ' ', ' ', 'a', 'a', 'a', 'a', ' '],
  52.         ['A', 'A', 'A', 'a', 'a', 'a', 'a', 'a', 'a']
  53.     ]
  54.  
  55.     :param pyramid_a: list
  56.     :param pyramid_b: list
  57.     :return: list
  58.     """
  59.     a = [pyramid_a, pyramid_b]
  60.     max_list = max(a, key=len)
  61.     min_list = min(a, key=len)
  62.     for _ in range(len(max_list) - len(min_list)):
  63.         a = [" " for _ in range(len(min_list[0]))]
  64.         min_list.insert(0, a)
  65.     return_list = []
  66.     for k, v in zip(pyramid_a, pyramid_b):
  67.         return_list.append(k + v)
  68.     return return_list
  69.  
  70.  
  71. def to_string(pyramid: list) -> str:
  72.     """
  73.     Return pyramid list as a single string.
  74.  
  75.     Join pyramid list together into a string and return it.
  76.     to_string(make_pyramid(3, 'A')) ->
  77.     '''
  78.      A
  79.     AAA
  80.     '''
  81.  
  82.     :param pyramid: list
  83.     :return: str
  84.     """
  85.     a = ""
  86.     for i in pyramid:
  87.         a += "".join(i) + "\n"
  88.     return a.rstrip("\n")
  89.  
  90.  
  91. if __name__ == '__main__':
  92.     pyramid_a = make_pyramid(3, "A")
  93.     # print(pyramid_a)  # ->
  94.     """
  95.     [
  96.         [' ', 'A', ' '],
  97.         ['A', 'A', 'A']
  98.     ]
  99.     """
  100.  
  101.     pyramid_b = make_pyramid(6, 'a')
  102.     # print(pyramid_b)  # ->
  103.     """
  104.     [
  105.         [' ', ' ', 'a', 'a', ' ', ' '],
  106.         [' ', 'a', 'a', 'a', 'a', ' '],
  107.         ['a', 'a', 'a', 'a', 'a', 'a']
  108.     ]
  109.     """
  110.  
  111.     joined = join_pyramids(pyramid_a, pyramid_b)
  112.     print(joined)  # ->
  113.     """
  114.     [
  115.         [' ', ' ', ' ', ' ', ' ', 'a', 'a', ' ', ' '],
  116.         [' ', 'A', ' ', ' ', 'a', 'a', 'a', 'a', ' '],
  117.         ['A', 'A', 'A', 'a', 'a', 'a', 'a', 'a', 'a']
  118.     ]
  119.     """
  120.  
  121.     # pyramid_string = to_string(joined)
  122.     # print(pyramid_string)  # ->
  123.     """
  124.          aa
  125.      A  aaaa
  126.     AAAaaaaaa
  127.     """
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top