Advertisement
mirovlad

Numbers In Pyramid

May 6th, 2022
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. import math
  2. nMax = input("Enter a positive integer: ")
  3. nMax = int(nMax)
  4. rMax = math.sqrt(nMax)
  5. rMax = math.ceil(rMax)
  6. print("To print numbers 1-" + str(nMax) + " in pyramid we need " + str(rMax) + " rows")
  7. n = 1
  8. numbersPerRow = 1
  9. for r in range(rMax):
  10.     if r > 0:
  11.         numbersPerRow += 2
  12.     # for s in range(rMax-r-1):
  13.     #     print("  ", end='')
  14.     print("  " * (rMax - r - 1), end='')
  15.     for c in range(numbersPerRow):
  16.         if n > nMax:
  17.             break
  18.         print(str(n) + " ", end='')
  19.         n += 1
  20.     print()  # Print new line
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement