Monday, December 13, 2021

Top 4 interview questions of python

 Write a program  on decorator?


def decor1(func):

    def wrapper():

        print("this is beauty function")

        func()

        

    return wrapper

    

  

def func1():

    print("this is the normal function")

    


func1 = decor1(func1)

func1()


#2. Write a code for fibonacci series upto 1000

a,b=0,1


while b<1000:

    print(b,end=',')

    a,b=b,a+b


output:

1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987


#3.Write a code for show the list indexes with list values?

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

for index,value in enumerate(list1):

    print("index-"+str(index)+" value-"+str(value))

output:

index-0 value-1

index-1 value-2

index-2 value-3

index-3 value-4

index-4 value-5



a = 99311278

list1=[]


def sort1(x):

    list1.append(b)

    list1.sort()

     

for i in range(1,9):

         b=a%10

         a =int(a/10)

         #print(a)

         #print(b)

         sort1(b)


print(list1)






    

python class topic video