Print rectangle pattern in python
Show In this shot, we will discuss how to generate a rectangle pattern using stars in Python. Numerous patterns can be printed using python, once we have a strong grip over the concepts involving loops. Here we will be using simple DescriptionTo execute a rectangular pattern using Python programming, we will use 2
CodeLet’s look at the code snippet below. # Initialising Length and Breadth rows = 3 columns = 6 # Loop through number of rows for i in range(rows): # Loop through number of columns for j in range(columns): # Printing Pattern print('*', end = ' ') print() Explanation
View Discussion Improve Article Save Article View Discussion Improve Article Save Article Given height h and width w, print a rectangular pattern as shown in the example below. Examples: Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@ The idea is to run two loops. One for the number of rows to be printed and the other for the number of columns. Print a ‘@’ only when the current row is first or last. OR the current column is first or last. C++
Java
Python3
PHP
Output @@@@@ @ @ @ @ @@@@@
This article is contributed by Anurag Rawat. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or if you want to share more information about the topic discussed above. How do you print a rectangular pattern?Algorithm to print rectangular star pattern using loop
Take the number of rows(N) and columns(M) of rectangle as input from user using scanf function. We will use two for loops to print rectangular star pattern. Outer for loop will iterate N times. In each iteration, it will print one row of pattern.
How do I print a python pattern program?Steps to Print Pattern in Python
Accept the number of rows from a user using the input() function to decide the size of a pattern. Next, write an outer loop to Iterate the number of rows using a for loop and range() function. Next, write the inner loop or nested loop to handle the number of columns.
How do you make a rectangle in Python?We can create a simple rectangle by defining a function that takes in two integers representing side length and side height. Then we can loop four times, using the forward() function to create a side representing either the length or height, then rotating the cursor 90 degrees with the right() function.
|