Python Program to print the pattern of numbers 1 12 123|Print the following number pattern using python|Python program to print pyramid pattern |Number pattern programs in python


Introduction

In this python program, we will learn how to print the following pattern using FOR and While Loop.


 

For Loop

for loop is used for iteration over a sequence (for example. a list, a tuple, a string or a dictionary).
But in this Code we have used it for incrementing numbers.To do so we have used the range() function.

The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a number specified by the user.

User can specify the Starting,end and the incrementation difference.


While Loop:

Using the while loop we can execute statements within the loop ,as long as the condition is true.




We Are Going to cover:-
  • how to print patterns in python using for loop
  • how to print number Pyramid patterns in python using while loop And for Loop.



Now let's ,move towards our main program

Source Code(Using "For " loop):-

n=int(input("enter number of rows needed:"))

for i in range(1,n+1):

    for j in range(1, i+1):

        print(j, end="")

    print()

#Code ends

Output:-(click to view clear image)

Executed on Pydroid3


Source Code(Using "While " loop):-

n = "1"

specifiednum = 1

while n != "123456":

print(n, end="")

specifiednum += 1

n += str(specifiednum)

print()

Output :-

Executed on IDLE(Python 3.9 64 bit)



"HOPE IT HELPED"

Have anything in mind? Let me 
know in the comment section👇

Next Post Previous Post
No Comment
Add Comment
comment url