Patterns using For Loop in Python


The program is creating a pattern using nested for loops in Python. The outer loop uses the range function to iterate 6 times and for each iteration, the inner loop also uses the range function to iterate 6 times. The print statement inside the inner loop is responsible for printing the "" character and the end='' parameter is used to prevent the cursor from moving to the next line after printing the "" character. The inner loop completes its 6 iterations and then the outer loop moves to the next iteration, printing a new line using the "\r" escape character. This process continues until the outer loop completes its 6 iterations, resulting in a pattern of 6 rows and 6 columns of "*" characters.

Source Code

for x in range(6):
  for y in range(6):
      print("*",end='')
  print("\r")
To download raw file Click Here

Output

******
******
******
******
******
******

Doller Pattern using For Loop

Source Code

for x in range(6):
    for y in range(6):
        print("$",end='')
    print("\r")
To download raw file Click Here

Output

$$$$$$
$$$$$$
$$$$$$
$$$$$$
$$$$$$
$$$$$$

Number Pattern using For Loop

Source Code

for x in range(6):
    for y in range(6):
        print(x,end='')
    print("\r")
To download raw file Click Here

Output

000000
111111
222222
333333
444444
555555

Number Pattern using For Loop

Source Code

for x in range(6):
    for y in range(6):
        print(y,end='')
    print("\r")
To download raw file Click Here

Output

012345
012345
012345
012345
012345
012345

Half Pyramid Star( * ) Pattern using For Loop

Source Code

for x in range(6):
   for y in range(x+1):
     print("*",end='')
   print("\r")
To download raw file Click Here

Output

 *
 *  *
 *  *  *
 *  *  *  *
 *  *  *  *  *
 *  *  *  *  *  *

Half Pyramid Doller($) Pattern using For Loop

Source Code

for x in range(6):
   for y in range(x+1):
     print(" $ ",end='')
   print("\r")
To download raw file Click Here

Output

 $
 $  $
 $  $  $
 $  $  $  $
 $  $  $  $  $
 $  $  $  $  $  $

Half Pyramid Number Pattern using For Loop

Source Code

for x in range(1,6):
   for y in range(1,x+1):
     print(" ",x,end='')
   print("\r")
   
To download raw file Click Here

Output

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

Half Pyramid Number Pattern using For Loop

Source Code

for x in range(1,6):
   for y in range(1,x+1):
     print(" ",y,end='')
   print("\r")
To download raw file Click Here

Output

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

Reverse Star( * ) using For Loop

Source Code

for x in range(6,-1,-1):
   for y in range(x+1):
     print(" * ",end='')
   print("\r")
To download raw file Click Here

Output

 *  *  *  *  *  *  *
 *  *  *  *  *  *
 *  *  *  *  *
 *  *  *  *
 *  *  *
 *  *
 *

Reverse Doller( $ ) using For Loop

Source Code

for x in range(6,-1,-1):
   for y in range(x+1):
     print(" $ ",end='')
   print("\r")
To download raw file Click Here

Output

 $  $  $  $  $  $  $
 $  $  $  $  $  $
 $  $  $  $  $
 $  $  $  $
 $  $  $
 $  $
 $

Reverse Number using For Loop

Source Code

for x in range(5,-1,-1):
   for y in range(1,x+1):
     print(" ",x,end='')
   print("\r")
   
To download raw file Click Here

Output

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

Reverse Number using For Loop

Source Code

for x in range(5,-1,-1):
   for y in range(1,x+1):
     print(" ",y,end='')
   print("\r")
   
To download raw file Click Here

Output

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