<- Back to the chapter.

Answer to Problem 4

Chapter 6, Section 1

Question:

Use two for loops, one of them nested, to print the following 5x10 rectangle:

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

This is a lot like the prior problem. Experiment with the ranges on the loops to find exactly what the range count controls.

Answer:

for i in range(10):
    for j in range(5):
        print("*", end=" ")
    print()
Output:
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

Explanation:

Video: Answer to Problem 4