Python Nested Loops To Print Rectangle With Asterisks

Python Nested Loops To Print Rectangle With Asterisks

Here you go! Try this!

num_rows = 2
num_cols = 3

for i in range(num_rows):
    print(*, end= )
    for j in range(num_cols-1):
        i*=j
        print(*, end= )
    print()

Youre trying to learn, I think, so a here is a hint to push you in the right direction.

You need to use a nested for loop. Use the range() builtin to produce an iterable sequence.

The outer for loop should iterate over the number of rows. The inner (nested) for loop should iterate over the columns.

Python Nested Loops To Print Rectangle With Asterisks

Sorry for resurrecting this thread, but im going through the same Zybooks course and the answer is actually a lot simpler than what was voted correct here.

num_rows = 2
num_cols = 3
for i in range(num_rows):
    for i in range(num_cols):
        print(*, end= )
    print()

Leave a Reply

Your email address will not be published. Required fields are marked *