• Register
2 votes


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

* * *
* * *

Thanks in advance

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

2 votes
Best answer


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):
        print('*', end=' ')

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.

13 9 6
94,240 points

Related questions

0 votes
1 answer 21 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.
asked Nov 29, 2020 Code Learner 5.3k points
1 vote
2 answers 257 views
Problem: Hello Kodlogs, I am a novice in computer programming. I started learning it using Python language. Today I’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.
asked Jul 6, 2020 adamSw 11.3k points
2 votes
1 answer 323 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.
asked Mar 17, 2020 Gavin 15.3k points
0 votes
1 answer 73 views
I need help with the basics, I need to print 1 to100 numbers in python. Please explain with the help of an example.
asked Oct 10, 2020 Ahsan 1.8k points
0 votes
1 answer 151 views
Problem : Looking for solution of following doubt if one for loop is nested within another, then the counter variables for the two loops should be
asked Nov 12, 2019 peterlaw 6.9k points
0 votes
1 answer 7 views
Problem: Hello When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop: Statement 1 is executed (100 time) before the execution of the code block. Statement 2 defines the condition for executing the code block. Statement 3 is executed (every time) after the code block has been executed.
asked Nov 3, 2020 Mashhoodch 5.6k points
0 votes
1 answer 23 views
Explain with an example?
asked Oct 8, 2020 jagruthi 680 points
0 votes
1 answer 13 views
Problem: Hello kodlogs, I am learning the python basic concept but while working on the string I having a doubt like how can I able to append to the string in the loops, I am having the list. list = ["alpha","beta","gamma","delta"] And how can we in inside a for loop I need to end with this: final_string ="firstsecondkodlogs" So, how can I achieved this.
asked Jun 10, 2020 Gavin 15.3k points
1 vote
1 answer 42 views
Problem: Hello Kodlogs, I am here with a problem. This could be a simple problem for you, guys, but it’s driving me crazy. I am in a situation that needs to print multiple values in a single line. Let me describe it in my words. Say, have some integer ... value in a different line and there is no option to concatenate them. Could you please help me out? Thanks for your concern and kind help.
asked Jun 2, 2020 adamSw 11.3k points
0 votes
1 answer 47 views
Problem: Hello guys, I am trying to understand deeply how two variables work inside a for-loop or iterate simultaneously? Where to use it and what is the purpose of it in a program?
asked May 31, 2020 adamSw 11.3k points