Print the following pattern

2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 

Here’s an example Python code to print the pattern you described:

# Define a variable to store the number of rows in the pattern
num_rows = 5

# Loop through each row of the pattern
for i in range(1, num_rows+1):
    # Print the i-th number i times
    for j in range(i):
        print(i, end=" ")
    # Print a newline character to move to the next row

In this code, we first define a variable num_rows to store the number of rows in the pattern.

We then use a nested loop to print the pattern. The outer loop iterates over each row of the pattern, from 1 to num_rows. The inner loop prints the i-th number (i.e., the value of the outer loop counter) i times, using the end parameter of the print() function to prevent it from adding a newline character after each number. Finally, we use another print() statement without any arguments to add a newline character and move to the next row.

When you run this code, it should output the following pattern:

2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 

Note that you can change the value of num_rows to print the pattern with a different number of rows.

Related Examples

1. Python Program to Print Hello world!

2. Calculate the multiplication and sum of two numbers

3. Python Program to Find the Square Root

4. Python Program to Calculate the Area of a Triangle

5. Python Program to Solve Quadratic Equation

6. Python Program to Swap Two Variables

7. Python Program to Generate a Random Number

8. Return the count of a given substring from a string

9. Python Program to check if the given number is a palindrome number

10. Python Program to print multiplication table form 1 to 10

11. Print downward Half-Pyramid Pattern with Star (asterisk)

12. Python Program to Convert Kilometers to Miles

13. Python Program to Check if a Number is Positive, Negative or 0

14. Python Program to Find the Sum of Natural Numbers

15. Print the sum of the current number and the previous number in Python

Leave a Reply

Your email address will not be published. Required fields are marked *

Wordpress Social Share Plugin powered by Ultimatelysocial
Wordpress Social Share Plugin powered by Ultimatelysocial