Friday, July 23, 2021

Function Practice

Function practice
In [ ]:
def areaSQR(s):
    return(s*s)
In [ ]:
def areaRect(l,b):
          return(l*b)
In [ ]:
def areaCir(r):
     print(3.14*r*r)
In [ ]:
def fact(n):
      f=1
      for i in range(2,n+1):
          f=f*i
      return(f)
In [ ]:
def Natsum(N):
    s=0
    for i in range(1,N+1):
        s+=i
    return(s)
In [ ]:
def Natsum(N):
    s=0
    for i in range(1,N+1):
        s+=i
    return(s)
In [ ]:
def ArPeriSq(s):
    a=s*s
    p=4*s
    return(a,p)
#r=ArPeriSq(4)
#print(r)
#A,P=ArPeriSq(3)
#print(A,P)
In [ ]:
def findint(L):
    c=0
    for i in L:
        if type(i)==int :
            c+=1
    return(c)
#li=[4,5,3.4,"indi",False,7]
#count=findint(li)
#print("number of int is",count)
#li=[4,5,3.4,"indi",False,7]
#count=findint(li)
#print("number of int is",count)
In [ ]:
ef joinlist(L1,L2):
     L1.extend(L2)
     return(L1)
pankaj=[4,5,3.4,"indi",False,7]
mokshi=[4,5,"indus",True,"hello"]
jesika=joinlist(pankaj,mokshi)
print(jesika)
In [ ]:
def fun(*k):
    print(type(k))
In [ ]:
def minstr(a,b,c):
       l1=len(a)
       l2=len(b)
       l3=len(c)

       if(l1<l2 and l1<l3):
             return(a)
       if(l2<l1 and l2<l3):
             return(b)
       if(l3<l1 and l3<l2):
             return(c)
#s=minstr("sdfds","kjsdjk","dfhdjshfjdshfj")

#print("min string is",s)
In [ ]:
def minlist(j,k):
    c=0
    t=0
    for i in j:
        if(type(i)==int):
            c+=1
    for i in k:
        if (type(i)==int):
            t+=1
    if(c<t):
        return(j)
    else:
        return(k)
y=minlist([5,6,7],[1,2])
print("minimmum length with int list",y)

No comments:

Post a Comment