Answer to Question #218780 in Python for binnu

Question #218780

Half Pyramid - 4

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.Input

The first line of input is an integer

N. The second line of input is an integer K.Explanation

In the example, the given starting number is

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


24

23 22

21 20 19

18 17 16 15

14 13 12 11 10


Sample Input 1

10

5

Sample Output 1

24

23 22

21 20 19

18 17 16 15

14 13 12 11 10




1
Expert's answer
2021-07-19T17:03:12-0400
row = int(input("Enter the total number of rows: ")) #Entering the number of rows e.g 5
number = int(input("Enter the start number ")) #Entering the start element e.g 10
#The below for loop helps to find the last number
for x in range(1, row+1):
    for y in range(1, x+1):
        
        number += 1
    
n = number - 1 
print()
for x in range(1, row+1):
    for y in range(1, x+1):
        print(n, end=" ")
        n -= 1
    print()

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