Py Prog
Py Prog
A-I)
l=[10,11,30,33,50,55]
even=[x for x in l if x%2==0]
print("even numbers in list are:",even)
odd=[x for x in l if x%2==1]
print("odd numbers in list are:",odd)
A-II)
l=[]
n=int(input("enter total elements in list:"))
for i in range(0,n):
x=int(input("enter a value"))
l.append(x)
print("the list is:",l)
even=[y for y in l if y%2==0]
print("even numbers in list are:",even)
odd=[y for y in l if y%2==1]
print("odd numbers in list are:",odd)
B-I)
x=[]
n=int(input("enter the size"))
for i in range(n):
x.append(int(input("enter the element")))
x.sort()
print(x)
z=[]
for j in range(n//2):
y=[]
y.append(x[n-j-1])
y.append(x[j])
z.append(tuple(y))
print("the result is:")
print(tuple(z))
B-II)
x=[]
n=int(input("enter the size"))
for i in range(n):
x.append(int(input("enter the element")))
x.sort()
print(x)
z=[]
for j in range(n//2):
y=[]
y.append(x[n-j-1])
y.append(x[j])
z.append(tuple(y))
print("the result is:")
print(tuple(z))
WEEK 6
A)
a='''~!@#$%^&*,./?(){}[]\<>'''
b=input("enter a string:")
c=""
for i in b:
if i not in a:
c=c+i
print("the updated string is:",c)
B)
n=input("enter a string:")
d={}
for i in n:
if i in d:
d[i]+=1
else:
d[i]=1
print("the dictionary with frequency of characters is:",d)
WEEK 7
B)
k=[]
n=int(input("enter total elements"))
for i in range(0,n):
x=int(input("enter a value"))
k.append(x)
print("the list is:",k)
s=map(lambda a:a**3,k)
print("the cube of elements in the list are:",tuple(s))
A)
a=int(input("enter a value"))
x=lambda a:a**3
print("cube of the number is:",x(a))
C)
l=[]
n=int(input("enter total elements"))
for i in range(0,n):
x=int(input("enter a value"))
l.append(x)
print("the list is:",l)
def odd(a):
if a%2==1:
return True
return False
s=filter(odd,l)
print("the odd numbers are:",tuple(s))
def even(a):
if a%2==0:
return True
return False
s=filter(even,l)
print("the even numbers are:",tuple(s))
WEEK 8
A)
def square(a):
return a*a
k=[]
n=int(input("enter total elements"))
for i in range(0,n):
x=int(input("enter a value"))
k.append(x)
print("the list is:",k)
s=map(square,k)
print("squares of the list is:",list(s))
B)
from itertools import combinations
#declaring a list of numbers
a=[1,2,3,4]
temp=combinations(a,2)
print("the combinations of given list {} is".format(a))
for i in list(temp):
print(i)
#declaring a list of strings
x=['u','b','c','d','e','f']
temp1=combinations(x,2)
print("the combinations of given list {}is".format(x))
for j in list(temp1):
print(j)
C)
from itertools import permutations
#declaring a list of numbers
x=[12,13,1]
temp=permutations(x)
print("all permutations of given list {}is".format(x))
for i in list(temp):
print(i)
a=permutations(x,2)
print("the permutations of given list {}is".format(x))
for i in list(a):
print(i)
y=('a','b','c')
temp1=permutations(y,3)
print("the permutations of given list {} is".format(y))
for j in list(temp1):
print(j)
WEEK 9
A)
def sum(*args):
s=0
for i in args:
s=s+i
return s
print("sum of {} and {} is:".format(1,2),sum(1,2))
print("sum of {},{} and {} is:".format(1,2,3),sum(1,2,3))
print("sum of {},{},{} and {} is:".format(1,2,3,4),sum(1,2,3,4))
print("sum of {},{},{},{} and {} is:".format(1,2,3,4,5),sum(1,2,3,4,5))
B)
l=[]
n=int(input("enter number of elements:"))
for i in range(n):
x=int(input("enter a number:"))
l.append(x)
print("the list is:",l)
from functools import reduce
print("sum of elements in the list are:",reduce(lambda x,y:x+y,l))