Thursday, December 10, 2020

pattern printing using for loop in python

 


number_of_stars=10


for i in range(5):

    

    for j in range(number_of_stars):

        if i<=j:

            print("",end=' ')

    for j in range(number_of_stars):

        if i>=j:

            print("*",end=' ')

    print()

for i in range(number_of_stars):

    for j in range(number_of_stars):

        if i>=j:

            print("",end=' ')

    for j in range(number_of_stars):

        if i<=j:

            if i<=4:

                print("*",end=' ')

    print()



     * 

         * * 

        * * * 

       * * * * 

      * * * * * 

 * * * * * * * * * * 

  * * * * * * * * * 

   * * * * * * * * 

    * * * * * * * 

     * * * * * * 

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:

    * 

    * * 

   * * * 

  * * * * 

 * * * * * 

 * * * * * 

  * * * * 

   * * * 

    * * 

     * 

python day 8 list

 '''

day 8 list ,tuples,



#example1:

    

fruits =[]

print(fruits)

print(type(fruits))



fruits =[1]

print(fruits)

print(type(fruits))




fruits =[1,2,3,3,3,3,3,3,3,3,3,3,3,3]

print(fruits)

print(type(fruits))



fruits =[1,2,3,4,5]

print(fruits[0])

print(fruits[1])

print(fruits[2])

print(fruits[3])

print(fruits[4])

print(type(fruits))



fruits =[1,2,3,4,5]

for i in range(5):

    print(fruits[i])


print(type(fruits))


fruits =[1,2,3,4,5]

print(id(fruits[0]))

print(id(fruits[1]))

print(id(fruits[2]))

print(id(fruits[3]))

print(id(fruits[4]))

#print(id(fruits[0]))



fruits =[1,2,3,4,5]

print(fruits[-1])

print(fruits[-2])

print(fruits[-3])

print(fruits[-4])

print(fruits[-5])


fruits=["mango","apple","banana","grapes","orange"]

print(fruits[0])

print(fruits[1])

print(fruits[2])

print(fruits[3])

print(fruits[4])

print(type(fruits))

print(fruits[-1])

print(fruits[-2])

print(fruits[-3])

print(fruits[-4])

print(fruits[-5])


flowers=["rose","lotus","lilli","jasmine","chamanthi"]

print(flowers[0])

print(flowers[1])

print(flowers[2])

print(flowers[3])

print(flowers[4])


fruits=["rose","lotus","lilli","jasmine","chamanthi"]

print(fruits[0])

print(fruits[1])

print(fruits[2])

print(fruits[3])

print(fruits[4])


flowers=["rose","lotus","lilli","jasmine","chamanthi"]


flowers.append("mandara")


flowers.append("chitti gulabi")

print(flowers[0])

print(flowers[1])

print(flowers[2])

print(flowers[3])

print(flowers[4])

print(flowers[5])

print(flowers[6])



flowers=["rose","lotus","lilli","jasmine","chamanthi"]

flowers.insert(0,"gilledu")

print(flowers[0])

print(flowers[1])

print(flowers[2])

print(flowers[3])

print(flowers[4])

print(flowers[5])



flowers=["rose","lotus","lilli","jasmine","chamanthi"]

flowers.insert(3,"gilledu")

print(flowers[0])

print(flowers[1])

print(flowers[2])

print(flowers[3])

print(flowers[4])

print(flowers[5])



flowers=["rose","lotus","lilli","jasmine","chamanthi"]

flowers.remove("chamanthi")

print(flowers[0])

print(flowers[1])

print(flowers[2])

print(flowers[3])



flowers=["rose","lotus","lilli","jasmine","chamanthi"]

flowers.pop(2)

print(flowers[0])

print(flowers[1])

print(flowers[2])

print(flowers[3])



flowers=["rose","lotus","lilli","jasmine","chamanthi"]

flowers.sort()

print(flowers[0])

print(flowers[1])

print(flowers[2])

print(flowers[3])




flowers=["rose","lotus","lilli","jasmine","chamanthi"]

flowers.reverse()

print(flowers[0])

print(flowers[1])

print(flowers[2])

print(flowers[3])

print(flowers[4])

'''

python class topic video