DeadlyChef

Untitled

Jul 25th, 2021
885
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. import sys
  3.  
  4. def drawRombWithNSize(n: int) -> list:
  5.     res = []
  6.     for i in range(n):
  7.         # skip 0 digit
  8.         currentNum = i + 1
  9.         # first add blank spaces for each num
  10.         line = " " * (n - i - 1) + "".join(
  11.             # add asc nums to the string
  12.             [str(j) if j < 10 else str(j)[-1] for j in range(1, currentNum)]
  13.             # plus desc nums
  14.             + [str(j) if j < 10 else str(j)[-1] for j in range(currentNum, 0, -1)]
  15.         )
  16.         # add to results
  17.         res.append(line)
  18.     # add the lower part of romb to res
  19.     # -2 is to skip the longest line
  20.     res = res + res[-2::-1]
  21.  
  22.     return res
  23.  
  24. try:
  25.     n = int(sys.argv[1])
  26. except (IndexError, ValueError):
  27.     n = int(input("Please input the size of romb: "))
  28.  
  29. print(*[row for row in drawRombWithNSize(n)], sep="\n")
  30.  
RAW Paste Data