Answer to Question #237601 in Python for pattern

Question #237601

Given an integer N as a starting number and K as input, write a program to print a number pyramid of K rows as shown below.

In the example, the given starting number is

10, and the number of rows in the pyramid is 5.So, the output should be

10 

11 12

13 14 15

16 17 18 19

20 21 22 23 24


1
Expert's answer
2021-09-15T05:16:21-0400


N = int(input("Enter starting Number  : "))
K = int(input("Enter Height of Pyramid: "))
i=0
for r in range(0,K+1):
    s=""
    for c in range(0,r):
        s=s + str(N+i)+" "
        i=i+1;
    print(s)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS