logo CodeStepByStep logo

random_rects

Language/Type: Python basics loops interactive programs
Author: Allison Obourn (on 2016/09/21)

Write a function named random_rects that asks a user how many rectangles they want and then prompts them for a width and height for each rectangle. It then outputs all of the rectangles made of ascii stars and their combined area. The user will be guaranteed to input valid positive integers for each value when prompted.

The following calls demonstrate your function's behavior. Bold text is user input. Your function should match this output format exactly:

call random_rects() random_rects()
output
How many rectangles? 3
Width 1? 2
Height 1? 3
**
**
**
Width 2? 3
Height 2? 2
***
***
Width 3? 10
Height 3? 1
**********
Total area: 22

How many rectangles? 4
Width 1? 5
Height 1? 2
*****
*****
Width 2? 4
Height 2? 2
****
****
Width 3? 3
Height 3? 2
***
***
Width 4? 2
Height 4? 2
**
**
Total area: 28
Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.