Anirudh Gottiparthy Anirudh Gottiparthy - 10 months ago 314
Python Question

Python Nested Loops To Print Rectangle With Asterisks

Write nested loops to print a rectangle. Sample output for given program:

3 stars : ***

3 stars : ***

I tried it and ended up with this:

num_rows = 2

num_cols = 3

print('*', end=' ')

Any help would be appreciated! Thanks!

Answer Source

You're 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.