Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- nMax = input("Enter a positive integer: ")
- nMax = int(nMax)
- rMax = math.sqrt(nMax)
- rMax = math.ceil(rMax)
- print("To print numbers 1-" + str(nMax) + " in pyramid we need " + str(rMax) + " rows")
- n = 1
- numbersPerRow = 1
- for r in range(rMax):
- if r > 0:
- numbersPerRow += 2
- # for s in range(rMax-r-1):
- # print(" ", end='')
- print(" " * (rMax - r - 1), end='')
- for c in range(numbersPerRow):
- if n > nMax:
- break
- print(str(n) + " ", end='')
- n += 1
- print() # Print new line
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement