Python Chapter Wise Codes
Python Chapter Wise Codes
IIMT UNIVERSITY
LAB MANUAL
[2024-25]
ROLL NO:2366001055
SN INDEX DATE SIGNATURE
1 Write a program of arithmetic operators +,-,*,/,%,**
exponent, // floor division
2 Write a program of comparison /relational operators-
>,<,==,>=,=<
3 Write a program of logical operators- and , or, not
a=int (input ("enter a first no. ")) b=int (input ("enter a second no. ")) print
(a+b) print (a-b) print (a/b) print (a*b) print (a/b) print (a%b) print (a**b) print
(a//b)
OUTPUT
15
1.1428571428571428
56
1.1428571428571428
2097152
PROGRAM 2
#Write a program of comparision /relational operators- >,<,==,>=,=<
if a>b:
else:
print ("b is maximum. ")
OUTPUT
b is maximum.
PROGRAM 3
if (a>b)or(a>c):
OUTPUT
thrid no. 6
c is maximum
PROGRAM 4
number. "))
b+=a
print(b)
OUTPUT
99
PROGRAM 5
if(type(a) is int):
else:
a is integer.
PROGRAM 6
,10,"abc",20,30,40,10.6,50]
if (a in list):
OUTPUT
enter a number.44
PROGRAM 7
print(bin(a&b),a&b)
OUTPUT
0b111000
0b110000 48
PROGRAM 8
print("even number")
else: print("odd
number")
OUTPUT
number PROGRAM
OUTPUT
second number"))
if(a>b):
print("a is maximum")
else:
print("b is maximum")
OUTPUT
is maximum
PROGRAM 11
print("b is maximum")
else:
print("c is maximum")
OUTPUT
is maximum
PROGRAM 12
print("a is +ve")
elif(a<0):
print("a is -ve")
else: print("a is
zero")
OUTPUT
a is +ve
PROGRAM 13
number")
OUTPUT
is middle number
PROGRAM 14
percentage=(((maths+english+hindi+science+sst)/Total)*100)
print("Fail")
OUTPUT
86.0 grade B
PROGRAM 15
#write a program in python to accept total sale amount and find the profit @5%
print("profit amount",profit)
OUTPUT
PROGRAM 16
#WAP in python input sales amount & calculate based on the given discount rate in python
amount discount
0-5000 5%
5000-10000 12%
25,000 30%
discount=amt*5/100 print("discount
amount",discount) print("payable
amount",amt-discount) elif(amt>=5000
and amt<10000):
discount=amt*12/100 print("discount
amount",discount) print("payable
amount",amt-discount)
discount=amt*12/100 print("discount
amount",discount) print("payable
amount",amt-discount)
discount=amt*30/100 print("discount
amount",discount) print("payable
amount",amt-discount) OUTPUT
PROGRAM 17
swapping",b)
temp=a a=b
b=temp
print("after swapping",b)
OUTPUT
before swapping 67
swapping 89 after
swapping 67
PROGRAM 18
OUTPUT
the breadth6
24.0
PROGRAM 19
print(pi*radius*radius)
OUTPUT
113.03999999999999
PROGRAM 20
OUTPUT
49
PROGRAM 21
OUTPUT
the breadth43
154.0
PROGRAM 22
print(2*pi*radius)
OUTPUT
213.52
PROGRAM 23
OUTPUT
268
PROGRAM 24
i=1
while(i<=10):
print(i)
i=i+1
OUTPUT
10
PROGRAM 25
i=10
while(i>=1):
print(i)
i=i-1
OUTPUT
10
PROGRAM 26
i=2
while(i<=20):
print(i)
i=i+2
OUTPUT
10
12
14
16
18
20
PROGRAM 27
i=1
while(i<=n):
print(i)
i=i+1
OUTPUT
PROGRAM 28
i=n
while(i>=1):
print(i)
i=i-1
OUTPUT
1
PROGRAM 29
sum=0
i=1
while(i<=n):
sum=sum+i
i=i+1
OUTPUT
PROGRAM 30
sum=0
i=1
while(i<=n):
sum=sum+i*i
i=i+1
PROGRAM 31
sum=0
i=1
while(i<=n):
sum=sum+i*i*i
i=i+1
OUTPUT
PROGRAM 32
sum=0
while(n>0):
x=n%10
sum=sum+x
n=n//10
OUTPUT
PROGRAM 33
product=1
while(n>0):
x=n%10
product=product*x
n=n//10
OUTPUT
sum=0
while(n>0):
x=n%10
sum=sum+x**2
n=n//10
OUTPUT
PROGRAM 35
sum=0
while(n>0):
x=n%10
sum=sum+x**3
n=n//10
PROGRAM 36
rev=0
i=int(input("enter a no : "))
while(i>0):
r=i%10
rev=rev*10+r
i=i//10
OUTPUT
enter a no : 134
PROGRAM 37
i=int(input("enter a no : "))
a,rev = i,0
while(i>0):
r=i%10
rev=rev*10+r
i=i//10
if(rev==a):
OUTPUT
enter a no : 121
Entered no is palindrome
PROGRAM 38
a=int(input("Enter a no : "))
fact=1
i=1
while(i<=a):
fact=fact*i
i=i+1
OUTPUT
Enter a no : 5
Factorial of 5 is : 120
PROGRAM 39
n=int(input("Enter a no : "))
a,b,c = 0,1,0
while(c<=n):
print(c)
a,b = b,c
c=a+b
OUTPUT
Enter a no : 5
PROGRAM 40
i=1
while(i<=3):
j=1
while(j<=3):
print(" * ",end="")
j=j+1
print(" ")
i=i+1
OUTPUT
* * *
* * *
* * *
PROGRAM 41
i=1
while(i<=4):
j=1
while(j<=i):
print(" * ",end="")
j=j+1
print(" ")
i=i+1
OUTPUT
* *
* * *
* * * *
PROGRAM 42
# write a program to print the pattern (3)
i=1
while(i<=4):
j=1
while(j<=4):
if j<=4-i:
else:
print("*",end=" ")
j=j+1
print(" ")
i=i+1
OUTPUT
* *
* * *
* * * *
PROGRAM 43
i=4
while(i>=1):
j=1
while(j<=i):
print(" * ",end="")
j=j+1
print(" ")
i=i-1
OUTPUT
* * * *
* * *
* *
PROGRAM 44
n=4
i=n
while i > 0:
if i > 0:
else:
print()
i -= 1
OUTPUT
****
***
**
PROGRAM 45
i=1
while(i<=3):
j=1
while(j<=i):
print(" * ",end="")
j=j+1
print(" ")
i=i+1
i=2
while(i>=1):
j=1
while(j<=i):
print(" * ",end="")
j=j+1
print(" ")
i=i-1
OUTPUT
* *
* * *
* *
PROGRAM 46
print("*",end=" ")
print(" ")
OUTPUT
***
*****
PROGRAM 47
print("*",end=" ")
print(" ")
OUTPUT
*****
***
PROGRAM 48
sum=0
row_no=int(input("enter a no : "))
sum=sum+1
print()
OUTPUT
enter a no : 4
1
23
456
7 8 9 10
PROGRAM 49
ch=64
row_no=int(input("enter a no : "))
ch=ch+1
print()
OUTPUT
enter a no : 4
A
BC
DEF
GHIJ
PROGRAM 50
ch=64
row_no=int(input("enter a no : "))
for row in range(1,row_no+1):
for column in range(1,row+1):
ch=ch+1
print(chr ( ch ),end=" ")
print()
for row in range(row_no+1,0,-1):
for column in range(1,row-1):
ch=ch+1
print(chr ( ch ),end=" ")
print()
OUTPUT
enter a no : 5
A
B C
D E F
G H I J
K L M N O
P Q R S
T U V
W X
Y
PROGRAM 51
OUTPUT
AYUSH GARG
PROGRAM 52
OUTPUT
PROGRAM 53
OUTPUT
different
PROGRAM 54
#write a program to print the string from selected index to selected index .
print(a[1:4])
OUTPUT
PROGRAM 55
OUTPUT
PROGRAM 56
OUTPUT
OUTPUT
PROGRAM 58
OUTPUT
PROGRAM 59
OUTPUT
OUTPUT
PROGRAM 61
#write a program to change the element of a fixed index in a list.
a=[1,53,32,"hello",23]
a[1]=222
print(a)
OUTPUT
PROGRAM 62
#write a program to insert element in the list.
a=[]
i=1
x=int(input("enter the size of the list : "))
while i <= x:
value=int(input("enter the element : "))
a.append(value)
i=i+1
print(a)
OUTPUT
enter the size of the list : 3
enter the element : 1
enter the element : 22
enter the element : 3
[1, 22, 3]
PROGRAM 63
# write a program to add element into the list at any index.
a=[]
i=1
x=int(input("enter the size of the list : "))
while i <= x:
value=int(input("enter the element : "))
a.append(value)
i=i+1
print("The entered element of the list is : ",a)
y=int(input("enter the index where you want to insert the element : "))
element=input("enter the element which you want to insert : ")
a.insert(y,element)
print("The new list after insertion is : ",a)
OUTPUT
PROGRAM 64
# write a program to delete a element from the list of any index.
a=[]
i=1
x=int(input("enter the size of the list : "))
while i <= x:
value=int(input("enter the element : "))
a.append(value)
i=i+1
print("The entered element of the list is : ",a)
y=int(input("enter the index no : "))
del a[y]
print("List after the deletion of an element : ",a)
OUTPUT
a=[]
i=1
x=int(input("enter the size of the list : "))
while i <= x:
value=int(input("enter the element : "))
a.append(value)
i=i+1
print("The entered element of the list is : ",a)
y=int(input("enter the index no : "))
a.pop(y)
print("List after pop an element : ",a)
OUTPUT
OUTPUT
enter the size of the list : 3
enter the element : 21
enter the element : 54
enter the element : 23
The entered element of the list is : [21, 54, 23]
YOU WANT TO CLEAR THE LIST: yes
your list is now clear : []
PROGRAM 67
# write a program to extend the list .
a=[]
b=[]
i=1
x=int(input("enter the size of the first list : "))
while i <= x:
value=(input("enter the element for first list: "))
a.append(value)
i=i+1
i=1
y=int(input("enter the size of the second list : "))
while i <= y:
valu=(input("enter the element for second list : "))
b.append(valu)
i=i+1
a.extend(b)
print("now your list is : ",a)
OUTPUT
enter the size of the first list : 3
enter the element for first list: 12
enter the element for first list: abc
enter the element for first list: iimt
enter the size of the second list : 4
enter the element for second list : helo
enter the element for second list : 12
enter the element for second list : 43
enter the element for second list : yo
now your list is : ['12', 'abc', 'iimt', 'helo', '12', '43', 'yo']
PROGRAM 68
#write a program to find the maximum and minimum of the entered list.
a=[]
y=int(input("enter the size of the list : "))
i=1
while i <= y:
value=(input("enter the element for list : "))
a.append(value)
i=i+1
print("maximum : ",max(a))
print("minimum : ",min(a))
OUTPUT
maximum : 32
minimum : 12
PROGRAM 69
# write a program to print the sum odd and even digit in a list.
even=0
odd=0
a=[]
y=int(input("enter the size of the list : "))
i=1
while (i <= y):
val=int(input("enter the element for list : "))
a.append(val)
if(val % 2 == 0):
even=even+val
else:
odd=odd+val
i=i+1
print("sum of odd : ",odd)
print("sum of even : ",even)
OUTPUT
enter the size of the list : 5
enter the element for list : 21
enter the element for list : 12
enter the element for list : 43
enter the element for list : 2
enter the element for list : 1
sum of odd : 65
sum of even : 14
PROGRAM 70
a=[]
y=int(input("enter the size of the list : "))
i=1
while (i <= y):
val=int(input("enter the element for list : "))
a.append(val)
i=i+1
print("list = ",a)
print("list in reverse order = ",a[::-1])
OUTPUT
enter the size of the list : 3
enter the element for list : 21
enter the element for list : 434
enter the element for list : 2
list = [21, 434, 2]
list in reverse order = [2, 434, 21]
PROGRAM 71
# write a program to count the frequency of entered no in a list.
f=0
a=[]
n=int(input("enter the no : "))
y=int(input("enter the size of the list : "))
i=1
while (i <= y):
val=int(input("enter the element for list : "))
a.append(val)
i=i+1
if(n==val):
f=f+1
print(f"The frequency of entered no {n} : ",f)
OUTPUT
enter the no : 23
enter the size of the list : 4
enter the element for list : 23
enter the element for list : 42
enter the element for list : 23
enter the element for list : 23
The frequency of entered no 23 : 3
PROGRAM 72
# write a program to find the total no of odd digit and total no of even digit.
o=0
e=0
a=[]
y=int(input("enter the size of the list : "))
i=1
while (i <= y):
val=int(input("enter the element for list : "))
a.append(val)
i=i+1
if(val%2==0):
e=e+1
else:
o=o+1
print(f"Total even digits : {e}\nTotal odd digits : {o}")
OUTPUT
enter the size of the list : 5
enter the element for list : 2
enter the element for list : 4
enter the element for list : 31
enter the element for list : 3
enter the element for list : 44
Total even digits : 3
Total odd digits : 2
PROGRAM 73
# write a program to remove duplicate elements from a list.
a=[]
b=[]
n=int (input ( "enter the size of the list : "))
i=0
while i<n:
val = int ( input("enter the element : "))
a.append(val)
i=i+1
i=0
while i<len(a):
if (a[i] not in b):
b.append(a[i])
i=i+1
print (b)
OUTPUT
enter the size of the list : 5
enter the element : 1
enter the element : 2
enter the element : 2
enter the element : 3
enter the element : 4
[1, 2, 3, 4]
PROGRAM 74
#write a program to print a tuple.
a=(1,2,34,644,12,"tuple")
print (a)
OUTPUT
(1, 2, 34, 644, 12, 'tuple')
PROGRAM 75
#write a program to take a tuple input from user and print it
a=()
b=list(a)
s=int(input ("enter the size of the tuple : "))
i=0
while i<s:
n=int(input("enter a value : "))
b.append(n)
i=i+1
a=tuple(b)
print (a)
OUTPUT
enter the size of the tuple : 5
enter a value : 2
enter a value : 4
enter a value : 21
enter a value : 54
enter a value : 32
(2, 4, 21, 54, 32)
PROGRAM 76
#write a program to add new element into the tuple.
a=()
b=list(a)
s=int(input ("enter the size of the tuple : "))
i=0
while i<s:
n=int(input("enter a value : "))
b.append(n)
i=i+1
a=tuple(b)
print ("The entered tuple is : ",a)
b=list(a)
newelement=input("enter the new element : ")
b.append(newelement)
a=tuple(b)
print("The new tuple is : ",a)
OUTPUT
enter the size of the tuple : 5
enter a value : 11
enter a value : 43
enter a value : 22
enter a value : 60
enter a value : 24
The entered tuple is : (11, 43, 22, 60, 24)
enter the new element : tuple
The new tuple is : (11, 43, 22, 60, 24, 'tuple')
PROGRAM 77
#write a program of tuple slicing.
a=()
b=list(a)
s=int(input ("enter the size of the tuple : "))
i=0
while i<s:
n=int(input("enter a value : "))
b.append(n)
i=i+1
a=tuple(b)
print ("The entered tuple is : ",a)
print ("The element of tuple from index 0 to 2 : ",a[0:2])
OUTPUT
enter the size of the tuple : 3
enter a value : 1
enter a value : 2
enter a value : 3
The entered tuple is : (1, 2, 3)
The element of tuple from index 0 to 2 : (1, 2)
The new tuple is : (1, 2, 3)
PROGRAM 78
#write a program to check whether it is a list or tuple.
a=(12,23,35,"tuple",2)
print(type(a))
OUTPUT
<class 'tuple'>
PROGRAM 79
#write a pogram to insert a element at any particular index in a list .
a=()
b=list(a)
s=int(input ("enter the size of the tuple : "))
i=0
while i<s:
n=int(input("enter a value : "))
b.append(n)
i=i+1
a=tuple(b)
print ("The entered tuple is : ",a)
b=list(a)
index=int(input("enter the index no where you want to insert an element : "))
newelement=input("enter the new element : ")
b.insert(index,newelement)
a=tuple(b)
print("The new tuple is : ",a)
OUTPUT
enter the size of the tuple : 3
enter a value : 23
enter a value : 54
enter a value : 33
The entered tuple is : (23, 54, 33)
enter the index no where you want to insert an element : 0
enter the new element : ayush
The new tuple is : ('ayush', 23, 54, 33)
PROGRAM 80
#write a pogram to change the element at any particular index in a list .
a=()
b=list(a)
s=int(input ("enter the size of the tuple : "))
i=0
while i<s:
n=int(input("enter a value : "))
b.append(n)
i=i+1
a=tuple(b)
print ("The entered tuple is : ",a)
b=list(a)
index=int(input("enter the index no where you want to insert an element : "))
newelement=int(input("enter the new element : "))
b[index]=(newelement)
a=tuple(b)
print("The new tuple is : ",a)
OUTPUT
enter the size of the tuple : 4
enter a value : 76
enter a value : 32
enter a value : 42
enter a value : 11
The entered tuple is : (76, 32, 42, 11)
enter the index no where you want to insert an element : 2
enter the new element : 100
The new tuple is : (76, 32, 100, 11)
PROGRAM 81
#write a program to delete a element from a tuple.
a=()
b=list(a)
s=int(input ("enter the size of the tuple : "))
i=0
while i<s:
n=int(input("enter a value : "))
b.append(n)
i=i+1
a=tuple(b)
print ("The entered tuple is : ",a)
b=list(a)
index=int(input("enter the index no : "))
del(b[index])
a=tuple(b)
print("The new tuple is : ",a)
OUTPUT
enter the size of the tuple : 3
enter a value : 21
enter a value : 45
enter a value : 33
The entered tuple is : (21, 45, 33)
enter the index no : 0
The new tuple is : (45, 33)
PROGRAM 82
#write a program to sort a tuple.
a=()
b=list(a)
s=int(input ("enter the size of the tuple : "))
i=0
while i<s:
n=int(input("enter a value : "))
b.append(n)
i=i+1
a=tuple(b)
print ("The entered tuple is : ",a)
c=sorted(a)
print("The new tuple is : ", tuple(c))
OUTPUT
enter the size of the tuple : 4
enter a value : 12
enter a value : 23
enter a value : 55
enter a value : 11
The entered tuple is : (12, 23, 55, 11)
The new tuple is : (11, 12, 23, 55)
PROGRAM 83
# write a program to find the maximum element from a tuple.
a=()
b=list(a)
s=int(input ("enter the size of the tuple : "))
i=0
while i<s:
n=int(input("enter a value : "))
b.append(n)
i=i+1
print("The maximum element of the tuple is " , max(b))
a=tuple(b)
OUTPUT
enter the size of the tuple : 4
enter a value : 23
enter a value : 88
enter a value : 65
enter a value : 33
The maximum element of the tuple is 88
PROGRAM 84
# write a program to find the minimum element from a tuple.
a=()
b=list(a)
s=int(input ("enter the size of the tuple : "))
i=0
while i<s:
n=int(input("enter a value : "))
b.append(n)
i=i+1
print("the minimum element of the tuple is : " , min(b))
a=tuple(b)
OUTPUT
enter the size of the tuple : 4
enter a value : 1
enter a value : 43
enter a value : 12
enter a value : 56
the minimum element of the tuple is : 1
PROGRAM 85
# write a program to make a dictionary .
d1 = {"model ":"i20" , "year : ":2020,"price : " :350000}
print (d1)
OUTPUT
{'model : ': 'i20', 'year : ': 2020, 'price : ': 350000}
PROGRAM 86
# write a program to input element in a dictionary from a user.
dic1 ={}
s = int(input("how many time you want to add element in a dictionary : "))
i=0
while i<s:
key = input("enter key : ")
value = input("enter value : ")
dic1[key]=value
i=i+1
print (dic1)
OUTPUT
how many time you want to add element in a dictionary : 3
enter key : name
enter value : rahul
enter key : age
enter value : 18
enter key : id
enter value : 2311876
{'name': 'rahul', 'age': '18', 'id': '2311876'}
PROGRAM 87
# write a program to print key of a dictionary .
dic1 ={}
s = int(input("how many time you want to add element in a dictionary : "))
i=0
while i<s:
key = input("enter key : ")
value = input("enter value : ")
dic1[key]=value
i=i+1
print (dic1.keys())
OUTPUT
how many time you want to add element in a dictionary : 3
enter key : name
enter value : rahul
enter key : age
enter value : 18
enter key : id
enter value : 2311232
dict_keys(['name', 'age', 'id'])
PROGRAM 88
# write a program to print values of a dictionary .
dic1 ={}
s = int(input("how many time you want to add element in a dictionary : "))
i=0
while i<s:
key = input("enter key : ")
value = input("enter value : ")
dic1[key]=value
i=i+1
print (dic1.values())
OUTPUT
how many time you want to add element in a dictionary : 3
enter key : name
enter value : rahul
enter key : age
enter value : 18
enter key : id
enter value : 2311232
dict_values(['rahul', '18', '2311232'])
PROGRAM 89
# write a program to print items of a dictionary .
dic1 ={}
s = int(input("how many time you want to add element in a dictionary : "))
i=0
while i<s:
key = input("enter key : ")
value = input("enter value : ")
dic1[key]=value
i=i+1
print (dic1.items())
OUTPUT
how many time you want to add element in a dictionary : 3
enter key : name
enter value : rahul
enter key : age
enter value : 18
enter key : id
enter value : 2123221
dict_items([('name', 'rahul'), ('age', '18'), ('id', '2123221')])
PROGRAM 90
# write a program to concatenate two dictionaries into one dictionary.
dic1 ={}
dic2 ={}
s = int(input("how many time you want to add element in first dictionary : "))
i=0
while i<s:
key = input("enter key : ")
value = input("enter value : ")
dic1[key]=value
i=i+1
r = int(input("how many time you want to add element in second dictionary : "))
i=0
while i<r:
key = input("enter key : ")
value = input("enter value : ")
dic2[key]=value
i=i+1
print ("The first dictionary is : " ,dic1.items())
print ("The second dictionary is : " ,dic2.items())
dic1.update(dic2)
print ("The concatenation of both dictionaries is : ",dic1)
OUTPUT
enter key : name
enter value : python
how many time you want to add element in second dictionary : 1
enter key : place
enter value : iimtu
The first dictionary is : dict_items([('name', 'python')])
The second dictionary is : dict_items([('place', 'iimtu')])
The concatenation of both dictionaries is : {'name': 'python', 'place': 'iimtu'}
PROGRAM 91
# write a program print a set.
a={1,2,3,"python"}
print (a)
OUTPUT
{1, 2, 3, 'python'}
PROGRAM 92
# write a program to check the type of a set.
a={1,2,3,"python"}
print (type(a))
OUTPUT
<class 'set'>
PROGRAM 93
# write a program to check the length of a set.
a={1,2,3,"python",23,344}
print ("The size of the set is : ",len(a))
OUTPUT
The size of the set is : 6
PROGRAM 94
# write a program of union of two sets.
a=set()
n=int(input("enter the size of the set 1 : "))
i=0
while i < n :
val=int(input("enter the element : "))
a.add(val)
i=i+1
print (a)
b=set()
j=int(input("enter the size of the set 2 : "))
i=0
while i < j :
val=int(input("enter the element : "))
b.add(val)
i=i+1
print (b)
u = a.union(b)
print ("The union of a and b is : " ,u)
OUTPUT
enter the size of the set 1 : 3
enter the element : 1
enter the element : 21
enter the element : 3
{1, 3, 21}
enter the size of the set 2 : 2
enter the element : 1
enter the element : 2
{1, 2}
The union of a and b is : {1, 2, 3, 21}
PROGRAM 95
# write a program of intersection of two sets.
a=set()
n=int(input("enter the size of the set 1 : "))
i=0
while i < n :
val=int(input("enter the element : "))
a.add(val)
i=i+1
print (a)
b=set()
j=int(input("enter the size of the set 2 : "))
i=0
while i < j :
val=int(input("enter the element : "))
b.add(val)
i=i+1
print (b)
ins = a.intersection(b)
print ("The intersection of a and b is : " ,ins)
OUTPUT
enter the size of the set 1 : 3
enter the element : 1
enter the element : 12
enter the element : 23
{1, 12, 23}
enter the size of the set 2 : 3
enter the element : 12
enter the element : 23
enter the element : 4
{12, 4, 23}
The intersection of a and b is : {12, 23}
PROGRAM 96
# write a program of difference of two sets.
a=set()
n=int(input("enter the size of the set 1 : "))
i=0
while i < n :
val=int(input("enter the element : "))
a.add(val)
i=i+1
print (a)
b=set()
j=int(input("enter the size of the set 2 : "))
i=0
while i < j :
val=int(input("enter the element : "))
b.add(val)
i=i+1
print (b)
dif = a. difference b)
print ("The difference of a and b is : " ,dif)
OUTPUT
enter the size of the set 1 : 3
enter the element : 1
enter the element : 2
enter the element : 3
{1, 2, 3}
enter the size of the set 2 : 3
enter the element : 11
enter the element : 2
enter the element : 32
{32, 2, 11}
The difference of a and b is : {1, 3}
PROGRAM 97
# write a program to check whether set a is the subset of set b.
a=set()
n=int(input("enter the size of the set 1 : "))
i=0
while i < n :
val=int(input("enter the element : "))
a.add(val)
i=i+1
print (a)
b=set()
j=int(input("enter the size of the set 2 : "))
i=0
while i < j :
val=int(input("enter the element : "))
b.add(val)
i=i+1
print (b)
dif = a. issubset (b)
print ("Is set a is the subset of set b : " ,dif)
OUTPUT
enter the size of the set 1 : 3
enter the element : 1
enter the element : 2
enter the element : 3
{1, 2, 3}
enter the size of the set 2 : 4
enter the element : 1
enter the element : 2
enter the element : 3
enter the element : 4
{1, 2, 3, 4}
Is set a is the subset of set b : True
PROGRAM 98
# write a program to check whether set a is the superset of set b.
a=set()
n=int(input("enter the size of the set 1 : "))
i=0
while i < n :
val=int(input("enter the element : "))
a.add(val)
i=i+1
print (a)
b=set()
j=int(input("enter the size of the set 2 : "))
i=0
while i < j :
val=int(input("enter the element : "))
b.add(val)
i=i+1
print (b)
dif = a. issuperset (b)
print ("Is set a is the superset of set b : " ,dif)
OUTPUT
enter the size of the set 1 : 3
enter the element : 1
enter the element : 2
enter the element : 3
{1, 2, 3}
enter the size of the set 2 : 2
enter the element : 1
enter the element : 2
{1, 2}
Is set a is the subset of set b : True
PROGRAM 99
# write a program to add two values using function with argument .
def sum(a,b):
print(“sum : “ , a+b)
n=int(input("enter a value : "))
i=int(input("enter a value : "))
sum(n,i)
OUTPUT
enter a value : 2
enter a value : 3
sum : 5
PROGRAM 100
# write a program to add two values using function without argument .
def sum():
a=int(input("enter the value 1 : "))
b=int(input("enter the value 2 : "))
print(a+b)
sum()
OUTPUT
enter the value 1 : 2
enter the value 2 : 3
sum : 5
PROGRAM 100
# write a program to add two values using function with parameter .
def sum(a,b):
print("sum :",a+b)
sum(3,4)
OUTPUT
sum : 7
PROGRAM 101
# write a program to add two values using function with no argument and no return .
def sum (a,b):
print(“sum “ ,a+b)
sum(2,3)
OUTPUT
Sum : 5
PROGRAM 102
# write a program to add two values using function with argument and no return .
def sum (a,b):
c=a+b
print("sum : ",c)
sum(2,3)
OUTPUT
sum : 5
PROGRAM 103
# write a program to add two values using function with no argument and return .
def sum ():
c=a+b
return c
a=int(input("enter a value : "))
b=int(input("enter a value : "))
d=sum()
print("sum : " , d)
OUTPUT
enter a value : 22
enter a value : 12
sum : 34
PROGRAM 104
# write a program to add two values using function with argument and return.
def sum(a,b):
return a+b
d=sum(3,4)
print("sum : ",d)
OUTPUT
sum : 7