Anirudh Gottiparthy Anirudh Gottiparthy - 1 year ago 763
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download