Patterns using nested For Loop in Python

for loop

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('')
**********
*********
********
*******
******
*****
****
***
**
*

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

* indicates required
Subscribe to plus2net

    plus2net.com



    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-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer