w3resource

Python Exercise: Construct the following pattern, using a nested loop number


44. Nested Loop Number Pattern

Write a Python program to construct the following pattern, using a nested loop number.

Pictorial Presentation:

Python Exercise: Construct the following pattern, using a nested loop number

Sample Solution:

Python Code:

# Iterate through a range from 0 to 9 (excluding 10)
for i in range(10):
    # Print the string representation of 'i' multiplied by 'i'
    print(str(i) * i)
	

Sample Output:

1                                                                                                             
22                                                                                                            
333                                                                                                           
4444                                                                                                          
55555                                                                                                         
666666                                                                                                        
7777777                                                                                                       
88888888                                                                                                      
999999999     

Flowchart :

Flowchart: Find the multiplication table of a number

For more Practice: Solve these Related Problems:

  • Write a Python program to print a pattern where the i-th line contains the number i repeated i times using nested loops.
  • Write a Python program to generate a numeric pattern with increasing numbers on each line where the line number dictates the repetition.
  • Write a Python program to use a nested for loop to print a pattern that starts at 1 and increments the repeated digit count on each new line.
  • Write a Python program to build a number pyramid where each row displays the row number repeated as many times as the row index.

Go to:


Previous: Write a Python program to create the multiplication table (from 1 to 10) of a number.
Next: Python functions Exercises

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.