DivisibleS by 2&3
abc = [1,5,4,6,8,11,3,12]
f=lambda x: (x%2 == 0) and (x%3 ==0)
xyz=list(filter(f,abc))
print(xyz) output-[6,12]
divisable:
a=int(input("Enter Number :"))
if(a%2==0):
print("Divisible by 2&3")
elif(a%3==0):
print("Divisible by3")
elif(a%2==0):
print("Divisible by2")
else:
print("Neither Divisible by 2&3")
greater number:
def maximum(a, b, c):
if (a >= b) and (a >= b):
largest = a
elif (b >= a) and (b >= a):
largest = b
else:
largest = c
return largest
a = 10
b = 14
c = 12
print(maximum(a, b, c))
greater than:
a=int(input("Enter a 1stNum:"))
b=int(input("Enter a 2ndNum:"))
c=int(input("Enter a 3rdNum:"))
if(a>b and a>c):
print("a is greater than b & c")
elif(b>c and b>a):
print("b is greater than c & a")
elif(c>a and c>b):
print("c is greater than a & b")
calcuis to ferehanhit:
a=[1,2,3,4,5]
ans=list(map(lambda b:9/5*b+32,a))
print(ans) output: [33.8, 35.6, 37.4, 39.2, 41.0]
addition of each character of list:
a = [1,3,4,5,6]
b= [2,4,5,6,7]
ans = list(map(lambda x,y:x+y,a,b))
print (ans) output: [3, 7, 9, 11, 13]
addition using VDF:
def addition(a,b):
c=a+b
return c
print("Function",c)
sum=addition(3,4)
sum1=addition('hi', ' jay')
sum2=addition('hi',' 3')
print (sum,sum1,sum2) output: 7 hi jay hi 3
square using argument fun:
def sqr(x):return x*x
def app(q,x):return q(x)
x1=app(sqr,7)
print(x1) output:49
break from particular latter:
for letter in 'python':
if letter == 'h':
break
print('current Letter :', letter) output: current Letter : p
current Letter : y
current Letter : t
Convert days into year and month:
a=int(input("Enter no of Days:"))
Enter no of Days:2000
>>> years=a//365
>>> years
>>> rem_d=a%365
>>> rem_d
175
>>> month=rem_d//30
>>> month
>>> rem_d%=30
>>> rem_d
25
>>> week=rem_d//7
>>> week
>>> days=rem_d%7
>>> days
Range :
a=list (range(1,100,2))
>>> a
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59,
61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99]
>>> a=list (range(2,100,2))
>>> a
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98]
>>> a=list (range(1,100,-2))
>>> a
[]
List addition:
a=[1,7,8,3,4]
i=0
sum=0
while(i<len(a)):
sum=sum+a[i]
i=i+1
print("sum",sum) output:23
odd even:
a=int(input("Please Enter a Number : "));
if(a%2==0):
print("This Number is Even")
else:
print("This Number is Odd")
power operation:
a=input("Enter first value=:")
b=input("Enter second value=:")
a=int(a)
b=int(b)
c=a**b
print(c)
square of given list:
def even(i):
ans = []
for n in i:
ans.append(n*n)
return ans
print(even([1,2,3,4,5])) output:[1,4,9,16,25]
square of given list:
a=[1,2,3,4,5]
ans=list(map(lambda x:x**2,a))
print(ans) output:[1,4,9,16,25]
prime number with range:
num =int(input("Enter the value:"))
if num > 1:
for i in range(2, num//2):
if (num % i) == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
else:
print(num, "is not a prime number")
sum of 1 to 100 using reduce:
from functools import *
a=range(1,101)
ans=reduce(lambda x,y:x+y,a)
print (ans) output:5050
sum of list using reduce:
from functools import *
a=[1,2,3,4,5]
ans=reduce(lambda x,y:x+y,a)
print (ans) output:15
tower of Hanoi:
def Tower(n,A,C,B):
if n==1:
print("Transfe disk" ,n, "from", A, "to", C)
else:
Tower(n-1,A,B,C)
print("Transfer disk", n, "from", A ,"to" , C)
Tower(n-1,B,C,A)
n= int (input("Enter number of disks:- "))
Tower (n,"A","C","B")
Spacing between character :
a=input ("enter a string:- ")
i=0
while (i<len(a)):
print(a[i] ,end=' ')
i=i+1
if (i<len(a)):
print(a[i])
i=i+1
pizza program:
s=int(200)
m=int(350)
l=int(500)
T=0
w="y"
while(w!="q"):
pizza=input("Enter your Pizza Size:-")
quantity=int(input("Enter Quantity:-"))
if(pizza=='s'):
T=T+int(200*quantity)
print("basic price is 200 & your total price is:-",T)
elif(pizza=='m'):
T=T+int(350*quantity)
print("basic price is 350 & your total price is:-",T)
elif(pizza=='l'):
T=T+int(500*quantity)
print("basic price is 500 & your total price is:-",T)
else:
print("please select given Pizza:-")
w=input("enter q wanna quit:-")
print("the total cost is",T)