Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Problem 6 Write a function hourglass that takes a positive integer parameter n, and then, using print statements, draw an hourglass shape of 2n

image text in transcribed

Python

Problem 6 Write a function hourglass that takes a positive integer parameter n, and then, using print statements, draw an hourglass shape of 2n lines, made of asterisks. For example, the call hourglass (4) should display the following Some hints: To make the hourglass shape, you'll have to print an appropriate number of spaces (to indent the stars), followed by an appropriate number of asterisks. If you know how many spaces and how many stars, you can use a statement like the following: print (numspaces+numasterisks"") . You'll have to carefully consider how many spaces and how many asterisks to print at each line. What is the relationship between n and the number of asterisks printed at the widest point? What is the relationship between the numbers of asterisks at a given line and the number of asterisks at the next line? What is the relationship between the number of spaces an a given line and the number of spaces at the next line It may be helpful to draw an hourglass by hand for n-5 in order to help visualize the mathematical relationships of the various parts Because of the symmetric nature of the picture (i.e. it gets narrower, then wider), you may want to consider using two separate loops: one for the narrowing part, another for the widening part. First write one, then the other

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions