Anirudh Gottiparthy Anirudh Gottiparthy - 2 months ago 97
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

'''IDK WHAT TO PUT HERE'''
print('*', end=' ')
print('')


Any help would be appreciated! Thanks!

Answer

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.

Comments