Patterns using nested For Loop in Python

Creating a simple string using for loop
for i in range(10):
  print('*',end='')  
Output
**********

pattern #1

for i in range(5): #change the range stop value for rows 
  for j in range(10): # change the range stop value for columns
    print('*',end='')  
  print('')
Output
**********
**********
**********
**********
**********

pattern #2

for i in range(10):
  for j in range(10-i):
    print('*',end='')  
  print('')
**********
*********
********
*******
******
*****
****
***
**
*
In above code use this line to print numbers in place of * .
print(j,end='')  

pattern #3

for i in range(1,10):
  for j in range(i):
    print('*',end='')  
  print('')
*
**
***
****
*****
******
*******
********
*********

pattern #4

for i in range(1,11):
  for k in range(i,10):
    print(' ',end='')
  for j in range(2*i-1):
    print('*',end='')
  print('')   
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************

pattern #5

for i in range(11,0,-1):
  for k in range(i,11):
    print(' ',end='')
  for j in range((2*i)-1):
    print('*',end='')
  print('')
*********************
 *******************
  *****************
   ***************
    *************
     ***********
      *********
       *******
        *****
         ***
          *

pattern #6

for i in range(0,12):
  for k in range(i,11):
    print('*',end='')  # left side 
  for j in range((2*i)): # 
    print(' ',end='')  # blank between 
  for k in range(i,11):
    print('*',end='')  # right side 
  print('')
**********************
**********  **********
*********    *********
********      ********
*******        *******
******          ******
*****            *****
****              ****
***                ***
**                  **
*                    *
Multiplication table using nested for loops
View and Download for_loop ipynb file ( .html format )
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    14-01-2023

    12345
    1234
    123
    12
    1

    02-10-2023

    12345
    1234
    123
    12
    1

    03-12-2023

    12345
    1234
    123
    12
    1

    06-12-2023

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

    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer