Thursday, December 10, 2020

square pattern printing using for loop in python

 # -*- coding: utf-8 -*-

"""

Created on Fri Dec 11 08:25:54 2020


@author: Onyx1

"""


for i in range(5):

    

    for j in range(5):

        if i<=j:

            print("",end=' ')

    for j in range(5):

        if i>=j:

            print("*",end=' ')

    print()

for i in range(5):

    

    for j in range(5):

        if i>=j:

            print("",end=' ')

    for j in range(5):

        if i<=j:

            print("*",end=' ')

    print()



output:

    * 

    * * 

   * * * 

  * * * * 

 * * * * * 

 * * * * * 

  * * * * 

   * * * 

    * * 

     * 

No comments:

Post a Comment

python class topic video