Question: PyNum first ask the user about the pyramid's height using the message 'What is the height of the pyramid? '. Let's call the pyramid


PyNum first ask the user about the pyramid's height using the message 'What is the height of the pyramid? '. Let's call the pyramid height h, which should be a positive integer. Next, PyNum prints a pyramid of height h with numbers as following: PyNum only prints a pyramid of numbers taller than 1 and shorter than 10. In other words, the user-provided input can not be smaller than 2 or greater than 9. If the user-provided value is not in the specified range, PyNum will let the user know using the message 'PyNum cannot help you!! . On the top of the pyramid and in the first line, PyNum will always print 1, as depicted in Figure 4. PyNume will print '1 2 3 ...n n-1 n-2... 1' in the nth line of pyramid. Let's assume h = 3, then, the first line of the pyramid will be 1. And second and third lines will be '1 2 1' and '1 2 3 2 1', respectively. Note that there is a white space between each pair of consequent numbers. Figure 4 shows a sample output of PyNum for h = 9. You must name your code file q4.py and upload it to the HW1Q4: Pyramid of Numbers section on Gradescope. What is the height of the pyramid? 9 1 12 1 1 2 3 2 1 1 2 3 4 3 2 1 2 3 4 5 4 3 2 1 1 1 2 3 4 5 6 5 1 2 3 4 5 6 7 6 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 8 4 3 2 1 5 4 3 2 1 6 5 4 3 2 1 7 6 5 4 3 2 1 HNE 48 1 2 3 4 7 height = int(input('What is the height of the pyramid? ')) for i in range(1, height+1): for j in range((height+1) - i): print(" ", end = " ") ~ M print(" ")
Step by Step Solution
There are 3 Steps involved in it
Program that prints a pyramid of numbers based on ... View full answer
Get step-by-step solutions from verified subject matter experts
