# Write a nested loop to print a rectangle.

274 views

## Problem:

Hi all, I am an entry-level student in Python programming. I have got an assignment from my lecturer to write a program that prints a diamond shape made of *. Well, I want to learn from the very basics. As I understood it might be the very basics of printing a diamond.
So, I want to write a nested loop program to print a rectangle. sample output for the given program
below:

``````* * *
* * *``````

## Solution:

Hello Gavin,

I come to know that you are an entry-level programming student, and you want to write a program that prints a rectangle with three columns and two rows. Yes, this is pretty basics of nested loop problems.
Let me walk you through my code below:

``````rows = 2
cols = 3

for m in range(rows):
print('*', end=' ')
for n in range(cols-1):
m*=n
print('*', end=' ')
print('')``````

Look into my codes very carefully, please. This nested loop will print a rectangle of two rows and three columns, as you are looking for.
First, for-loop will produce the rows and the second one will the columns.

I hope you get me. Thanks.

## Related questions

3 views
Problem: Anyone here who know nested loops to print a rectangle. sample output for given program? If yes, then please answer me.
6 views
7 views
48 views
Problem: I just started Bachelors in Software Engineering. Programming is the main subject of Software Engineering and I have no prior knowledge of programming. My programming teacher gave me an assignment in which I have to write a program in C++ whose output should be as ... a hint: Use nested loop. If someone knows how to do this kindly explain and provide me with the example program. Thanks.
1 vote
949 views
Problem: Hello Kodlogs, I am a novice in computer programming. I started learning it using Python language. Today I&rsquo;ve got an assignment to make a program using given the number of rows and the number of columns, write nested loops to print a rectangle. Now, my ... number. Could you please help me in this regard? How would I do that? Thanks for reading my problem, and helping me. Thanks.
1 vote
18 views
Problem: Its hard for me to figure out this problem; Print the two-dimensional list mult_table by row and column. hint: use nested loops.
651 views
Problem: Hello good soul, I am a newbie in python programming. I am having a problem printing both the name on the list and the email. Let me put it this way, I want to write a for loop to print each contact in contact_emails. Any solution will be much appreciated. Thanks.