Question: Write a recursive function hourglass ( base ) that prints an hour glass to the screen using asterisks. The function has a single paramater, base,

Write a recursive function hourglass(base) that prints an hour glass to the screen using asterisks. The function has a single paramater, base, an int which indicates how many asterisks will be used at the top and bottom levels of the hour glass. Each successive level of the hourglass should have two fewer asterisks in it. The successive levels should be centered. Once the level has 1 or 2 asterisks it should repeat that level, then invert and grow by two asterisks until it reaches the base level. This should work for both even and odd inputs.
Hint: you may find the .center() method on str useful. Call help(str.center) to learn more about it.
Hint2: you may find it useful to use an auxiliary function (sometimes called a helper function). This is a technique that allows you to offload your recursion to a second function that has additional parameters that enable you to make the problem easier to solve. In this case, imagine if the body of hourglass simply called another function: hourglass_helper(base, current_level) which would allow you to track how many levels youve printed so far. In this case, hourglass offloads the recursion to hourglass_helper which is where youd define your base and recursive cases.
You do not have to deal with inputs less than 3.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!