KEMBAR78
Python Chapter Wise Codes | PDF | Discrete Mathematics | Mathematics
0% found this document useful (0 votes)
9 views74 pages

Python Chapter Wise Codes

This document is a lab manual for IIMT University, detailing various programming exercises in Python for the academic year 2024-25. It includes a comprehensive list of tasks involving arithmetic, comparison, logical, assignment, identity, membership, and bitwise operators, as well as programs for calculating areas, percentages, and generating patterns. Each program is accompanied by example input and output to illustrate functionality.

Uploaded by

yj1750324
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views74 pages

Python Chapter Wise Codes

This document is a lab manual for IIMT University, detailing various programming exercises in Python for the academic year 2024-25. It includes a comprehensive list of tasks involving arithmetic, comparison, logical, assignment, identity, membership, and bitwise operators, as well as programs for calculating areas, percentages, and generating patterns. Each program is accompanied by example input and output to illustrate functionality.

Uploaded by

yj1750324
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

IMT UNIVERSITY, MEERUT, UTTAR PRADESH

IIMT UNIVERSITY

LAB MANUAL
[2024-25]

SUBMITTED BY: SUBMITTED TO:


NAME: AYUSH GARG Mr. SHASHANK SHARMA

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

4 Write a program of Assignment operators - = ,


+=,=,*=,/=,**=,//=
5 Write a program of Identity operators - is, is not

6 Write a program of Membership Operators - in , not in

7 Write a program of Bitwise Operators- & and , or ,XOR

8 Write a program to find even or odd number

9 Write a program to class for voting eligible

10 Write a program to find maximum number between two


number
11 Write a program to find maximum number between
three number
12 Write a program to check the is +ve,-ve,0

13 Write a program to find the middle of 3 number of group

14 Write a program to calculate the percentage

15 write a program in python to accept total sale amount


and find the profit @5%
16 WAP in python input sales amount & calculate based on
the given discount rate in python
17 Write a program to swap values of two number

18 write a program in python find the area of rectangle

19 write a program in python find the area of circle

20 write a program in python find the area of square

21 write a program in python find the perimeter of rectangle

22 write a program in python find the perimeter of circle

23 write a program in python find the perimeter of square


24 write a program in python to print no from 1 to 10

25 write a program in python to print no from 10 to 1

26 write a program in python to print no from 2 to 20

27 write a program in python to print no from 1 to n

28 Write a program in python to print no


from n to 1

29 write a program to find the sum of no from 1 to n

30 Write a program to find the sum of square


of no from 1 to n

31 Write a program to find the sum of cube


of no from 1 to n

32 Write a program to print the sum of digit


of entered no

33 write a program to print the product of digit of entered


no
34 write a program to print the sum of square of digit of
entered no
35 write a program to print the sum of cube of digit of
entered no
36 write a program to reverse the entered no

37 write a program to check whether the no is palindrome


or not
38 write a program to print the factorial of
entered no

39 write a program to print Fibonacci series

40 write a program to print the pattern (1) :- * * *


***
***
41 write a program to print the pattern (2) :-
*
**
***
****
42 write a program to print the pattern (3) :-
*
**
***
43 write a program to print the pattern (4) :-
****
***
**
*
44 write a program to print the pattern (5) :-
****
***
**
*
45 write a program to print the pattern (6) :-
*
**
***
**
*

46 write a program to print the pattern (7) :-


*
***
*****
47 write a program to print the pattern (8) :-
*****
***
*

48 write a program to print the pattern (9) :-


1
2 3
4 5 6
7 8 9 10
49 write a program to print the pattern (10) :-
A
B C
D E F
G H I J
PROGRAM 1

#Write a program of arithmetic operators +,-,*,/,%,** exponent, // floor division

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

enter a first no. 8

enter a second no. 7

15

1.1428571428571428

56

1.1428571428571428

2097152

PROGRAM 2
#Write a program of comparision /relational operators- >,<,==,>=,=<

a=int (input ("enter a first no. "))

b=int (input ("enter a second no. "))

if a>b:

print ("a is maximum. ")

else:
print ("b is maximum. ")

OUTPUT

enter a first no. 3

enter a second no. 4

b is maximum.

PROGRAM 3

Write a program of logical operators- and , or, not

a=int (input ("enter a first no. ")) b=int (input

("enter a second no. ")) c=int (input ("enter a

thrid no. "))

if (a>b)or(a>c):

Print ( "a is maximum. ")


elif (b>a) and (b>c) : Priat

("b is maximum. ")

print (" c is maximum. ")

OUTPUT

enter a first no. 4 enter

a second no. 5 enter a

thrid no. 6

c is maximum

PROGRAM 4

#Write a program of Assignment operators - =,+=,-=,*=,/=,**=,//=

a=int(input("enter a first number. ")) b=int(input("enter a second

number. "))

b+=a

print(b)

OUTPUT

enter a first number. 43

enter a second number. 56

99

PROGRAM 5

#Write a program of Identity operators - is, is not a=eval

(input("enter a number. "))

if(type(a) is int):

print(" a is integer. ")

else:

print("a is not integer. ")


OUTPUT

enter a number. 454

a is integer.

PROGRAM 6

#Write a program of Membership Operators - in , not in

a=input("enter a number.") list=["Hello"

,10,"abc",20,30,40,10.6,50]

if (a in list):

print("a are present in in the list ") else:

print("a is not present in this list")

OUTPUT

enter a number.44

a is not present in this list

PROGRAM 7

#Write a program of Bitwise Operators- & and , or ,XOR

a=int(input("enter a first number.")) b=int(input("enter a

second number.")) print(bin(a)) print(bin(b))

print(bin(a&b),a&b)

OUTPUT

enter a first number.54

enter a second number.56


0b110110

0b111000

0b110000 48

PROGRAM 8

#Write a program to find even or odd number

a=int(input("enteer a number")) if(a%2==0):

print("even number")

else: print("odd

number")

OUTPUT

enter a number67 odd

number PROGRAM

'''#Write a program to class for voting eligible

a=int(input("enter the age")) if (a>18):

print("eligible for voting") else:

print("not eligible for voting")

OUTPUT

enter the age13 not

eligible for voting


PROGRAM 10

#Write a program to find maximum number between two number

a=int(input("enter first number")) b=int(input("enter

second number"))

if(a>b):

print("a is maximum")

else:

print("b is maximum")

OUTPUT

enter first number45

enter second number56 b

is maximum

PROGRAM 11

#Write a program to find maximum number between three number

a=int(input("enter first number"))

b=int(input("enter second number"))

c=int(input("enter third number"))

if((a>b) and (a>c)): print("a is

maximum") elif((b>a) and (b>c)):

print("b is maximum")

else:

print("c is maximum")

OUTPUT

enter first number54

enter second number34


enter third number56 c

is maximum

PROGRAM 12

#Write a program to check the is +ve,-ve,0

a=int(input("enter the number")) if(a>0):

print("a is +ve")

elif(a<0):

print("a is -ve")

else: print("a is

zero")

OUTPUT

enter the number56

a is +ve
PROGRAM 13

#Write a program to find the middle of 3 number of group

a=int(input("enter the first number")) b=int(input("enter

the second number")) c=int(input("enter the third

number")) if((a>b) and(a<c) or (a<b) and (a>c)):

print("a is middle number") elif((b>a)

and (b<c) or (b<a) and(b>c)):

print("b is middle number")

else: print("c is middle

number")

OUTPUT

enter the first number56

enter the second number78

enter the third number89 b

is middle number

PROGRAM 14

#Write a program to caluclate the percentage maths=

int(input("enter the marks of maths"))

english=int(input("enter the marks of english"))

hindi=int(input("enter the marks of hindi"))

science=int(input("enter the marks of science"))

sst=int(input("enter the marks of sst")) Total=int(input("enter

the marks of Total"))

percentage=(((maths+english+hindi+science+sst)/Total)*100)

print(percentage) if (percentage>=90): print("grade A")


elif(percentage >=80): print("grade B") elif(percentage

>=70): print("grade C") elif(percentage>=60):

print("grade D") elif(percentage>=50): print("grade E")

elif(percentage >=40): print("grade F") else:

print("Fail")

OUTPUT

enter the marks of maths78

enter the marks of english89

enter the marks of hindi98

enter the marks of science87

enter the marks of sst78

enter the marks of Total500

86.0 grade B
PROGRAM 15

#write a program in python to accept total sale amount and find the profit @5%

total_sale=int(input("enter a total sale amount")) profit=total_sale*5/100

print("profit amount",profit)

OUTPUT

enter a total sale amount79

profit amount 3.95

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%

10,000-20,000 20% 20,000-

25,000 30%

amt=int(input("enter the sale amount"))

if(amt>0 and amt<5000):

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)

elif(amt>=10000 and amt<20000):

discount=amt*12/100 print("discount

amount",discount) print("payable

amount",amt-discount)

elif(amt>=20000 and amt<25000):

discount=amt*30/100 print("discount

amount",discount) print("payable

amount",amt-discount) OUTPUT

enter the sale amount7000

discount amount 840.0

payable amount 6160.0

PROGRAM 17

#Write a program to swap values of two number

a=int(input("enter a first number"))

b=int(input("enter a second number"))

print("before swapping",a) print("before

swapping",b)

temp=a a=b

b=temp

print("after swapping ",a)

print("after swapping",b)
OUTPUT

enter a first number67

enter a second number89

before swapping 67

before swapping 89 after

swapping 89 after

swapping 67

PROGRAM 18

#write a program in python find the area of rectangle

length=float(input("enter the length"))

breadth=float(input("enter the breadth")) print(length*breadth)

OUTPUT

enter the length4 enter

the breadth6

24.0

PROGRAM 19

#write a program in python find the area of circle

radius=int(input("enter the radiu")) pi=3.14

print(pi*radius*radius)

OUTPUT

enter the radiu6

113.03999999999999
PROGRAM 20

#write a program in python find the area of square

side=int(input("enter the side")) print(side*side)

OUTPUT

enter the side7

49

PROGRAM 21

#write a program in python find the perimeter of rectangle

length=float(input("enter the length")) breadth=float(input("enter

the breadth")) print(2*(length+breadth))

OUTPUT

enter the length34 enter

the breadth43

154.0
PROGRAM 22

#write a program in python find the perimeter of circle

radius=int(input("enter the radius")) pi=3.14

print(2*pi*radius)

OUTPUT

enter the radius34

213.52

PROGRAM 23

#write a program in python find the perimeter of square

side=int(input("enter the side")) print(4*side)

OUTPUT

enter the side67

268
PROGRAM 24

#write a program in python to print no from 1 to 10

i=1

while(i<=10):

print(i)

i=i+1

OUTPUT

10
PROGRAM 25

#write a program in python to print no from 10 to 1

i=10

while(i>=1):

print(i)

i=i-1

OUTPUT

10

PROGRAM 26

#write a program in python to print no from 2 to 20

i=2

while(i<=20):

print(i)

i=i+2
OUTPUT

10

12

14

16

18

20

PROGRAM 27

#write a program in python to print no from 1 to n

n=int(input("Enter the limit : "))

i=1

while(i<=n):

print(i)

i=i+1
OUTPUT

Enter the limit : 5

PROGRAM 28

#write a program in python to print no from n to 1

n=int(input("Enter the limit : "))

i=n

while(i>=1):

print(i)

i=i-1

OUTPUT

Enter the limit : 5

1
PROGRAM 29

# write a program to find the sum of no from 1 to n

sum=0

n=int(input("Enter the limit : "))

i=1

while(i<=n):

sum=sum+i

i=i+1

print("The sum from 1 to n :",sum)

OUTPUT

Enter the limit : 5

The sum from 1 to n : 15

PROGRAM 30

# write a program to find the sum of square of no from 1 to n

sum=0

n=int(input("Enter the limit : "))

i=1

while(i<=n):

sum=sum+i*i

i=i+1

print("The sum of square of no from 1 to n :",sum)


OUTPUT

Enter the limit : 5

The sum of square of no from 1 to n : 55

PROGRAM 31

# write a program to find the sum of cube of no from 1 to n

sum=0

n=int(input("Enter the no : "))

i=1

while(i<=n):

sum=sum+i*i*i

i=i+1

print("The sum of cube of no from 1 to n :",sum)

OUTPUT

Enter the limit : 5

The sum of cube of no from 1 to n : 225

PROGRAM 32

# write a program to print the sum of digit of entered no

sum=0

n=int(input("Enter the no : "))

while(n>0):
x=n%10

sum=sum+x

n=n//10

print("The sum of digit of entered no :",sum)

OUTPUT

Enter the no : 123

The sum of digit of entered no : 6

PROGRAM 33

# write a program to print the product of digit of entered no

product=1

n=int(input("Enter the no : "))

while(n>0):

x=n%10

product=product*x

n=n//10

print("The sum of digit of entered no :",product)

OUTPUT

Enter the no : 123

The product of digit of entered no : 6


PROGRAM 34

# write a program to print the sum of square of digit of entered no

sum=0

n=int(input("Enter the no : "))

while(n>0):

x=n%10

sum=sum+x**2

n=n//10

print("The sum of digit of entered no :",sum)

OUTPUT

Enter the no : 123

The sum of digit of entered no : 14

PROGRAM 35

# write a program to print the sum of cube of digit of entered no

sum=0

n=int(input("Enter the no : "))

while(n>0):

x=n%10

sum=sum+x**3

n=n//10

print("The sum of digit of entered no :",sum)


OUTPUT

Enter the no : 123

The sum of digit of entered no : 36

PROGRAM 36

# write a program to reverse the entered no

rev=0

i=int(input("enter a no : "))

while(i>0):

r=i%10

rev=rev*10+r

i=i//10

print("Reverse of the entered no is : ",rev)

OUTPUT

enter a no : 134

Reverse of the entered no is : 431

PROGRAM 37

# write a program to check whether the no is palindrome or not

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):

print("Entered no is palindrome ")

else: print("Entered no is not palindrome ")

OUTPUT

enter a no : 121

Entered no is palindrome

PROGRAM 38

# write a program to print the factorial of entered no

a=int(input("Enter a no : "))

fact=1

i=1

while(i<=a):

fact=fact*i

i=i+1

print("Factorial of",a,"is : ",fact)

OUTPUT

Enter a no : 5

Factorial of 5 is : 120
PROGRAM 39

# write a program to print Fibonacci series

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

# write a program to print the pattern (1)

i=1

while(i<=3):

j=1

while(j<=3):

print(" * ",end="")

j=j+1
print(" ")

i=i+1

OUTPUT

* * *

* * *

* * *

PROGRAM 41

# write a program to print the pattern (2)

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:

print(" ",end=" ")

else:

print("*",end=" ")

j=j+1

print(" ")

i=i+1

OUTPUT

* *

* * *

* * * *

PROGRAM 43

# write a program to print the pattern (4)

i=4

while(i>=1):

j=1

while(j<=i):
print(" * ",end="")

j=j+1

print(" ")

i=i-1

OUTPUT

* * * *

* * *

* *

PROGRAM 44

# write a program to print the pattern (5)

n=4

i=n

while i > 0:

if i > 0:

print(" " * (n - i) + "*" * i)

else:

print()

i -= 1

OUTPUT
****

***

**

PROGRAM 45

# write a program to print the pattern (6)

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

# write a program to print the pattern (7)

for i in range (1,4):

for k in range (1,4-i):

print(" ",end=" ")

for j in range (1,(2*i-1)+1):

print("*",end=" ")

print(" ")

OUTPUT

***

*****

PROGRAM 47

# write a program to print the pattern (8)

for i in range (3,0,-1):


for k in range (1,4-i):

print(" ",end=" ")

for j in range (1,(2*i-1)+1):

print("*",end=" ")

print(" ")

OUTPUT

*****

***

PROGRAM 48

# write a program to print the pattern (9)

sum=0

row_no=int(input("enter a no : "))

for row in range(1,row_no+1):

for column in range(1,row+1):

sum=sum+1

print(format ( sum ),end=" ")

print()

OUTPUT

enter a no : 4

1
23

456

7 8 9 10

PROGRAM 49

# write a program to print the pattern (10)

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()

OUTPUT

enter a no : 4
A
BC
DEF
GHIJ

PROGRAM 50

# write a program to print the pattern (11)

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

# write a program to perform string concatination

name1 = "AYUSH "


name2 = "GARG"
print(name1 + name2)

OUTPUT

AYUSH GARG

PROGRAM 52

#write a progam to perform string replication.

name = "PYTHON "


print (5*name)

OUTPUT

PYTHON PYTHON PYTHON PYTHON PYTHON

PROGRAM 53

#write a progam to perform string comparison

name1 = "AYUSH "


name2 = "GARG"
if(name1==name2):
print("same")
else:
print("different")

OUTPUT

different
PROGRAM 54

#write a program to print the string from selected index to selected index .

a=(input (" enter a string : "))

print(a[1:4])

OUTPUT

enter a string : hero honda

selected string is : ero

PROGRAM 55

#write a program to find the length of a string.

a=(input ("enter a string : "))


print( "length of string is : ",len(a))

OUTPUT

enter a string : hello how are you


length of string is : 17

PROGRAM 56

#write a program to convert a string into upper case.

a=(input ("enter a string : "))


print( "upper case of string is : ",a.upper())

OUTPUT

enter a string : hEllO HoW arE YOu


upper case of string is : HELLO HOW ARE YOU
PROGRAM 57

#write a program to convert a string into lower case.

a=(input ("enter a string : "))


print( "upper case of string is : ",a.lower())

OUTPUT

enter a string : hEllO HoW arE YOu


upper case of string is : hello how are you

PROGRAM 58

#write a program to convert a string into capitalize.

a=(input ("enter a string : "))


print( "upper case of string is : ",a.capitalize())

OUTPUT

enter a string : hEllO HoW arE YOu


upper case of string is : Hello how are you

PROGRAM 59

#write a program to reverse a string.

a=(input ("enter a string : "))


print( "reverse of string is : ",a[::-1])

OUTPUT

enter a string : hero honda


reverse of string is : adnoh oreh
]PROGRAM 60
#write a program to print a list.
a=[1,53,32,"hello",23]
print(a)

OUTPUT

[1, 53, 32, 'hello', 23]

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

[1, 222, 32, 'hello', 23]

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

enter the size of the list : 3


enter the element : 1
enter the element : 2
enter the element : 3
The entered element of the list is : [1, 2, 3]
enter the index where you want to insert the element : 1
enter the element which you want to insert : abc
The new list after insertion is : [1, 'abc', 2, 3]

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

enter the size of the list : 3


enter the element : 1
enter the element : 5
enter the element : 3
The entered element of the list is : [1, 5, 3]
enter the index no : 0
List after the deletion of an element : [5, 3]
PROGRAM 65

# write a program to pop 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 : "))
a.pop(y)
print("List after pop an element : ",a)

OUTPUT

enter the size of the list : 3


enter the element : 2
enter the element : 5
enter the element : 3
The entered element of the list is : [2, 5, 3]
enter the index no : 2
List after pop an element : [2, 5]
PROGRAM 66

#write a program to clear 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("The entered element of the list is : ",a)
y=(input("YOU WANT TO CLEAR THE LIST: "))
yes="yes"
if(y=="yes"):
a.clear()
print("your list is now clear :",a)
else:
print("List is not clear ",a)

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

#write a program to print a list in reverse order

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

You might also like