Term 2 - Practical Programs 2021
Term 2 - Practical Programs 2021
Write a python program to find the largest and smallest number in a list.
AIM:
To write a python program to find the largest and smallest number in a list.
SOURCE CODE:
lst = []
for n in range(num):
lst.append(numbers)
print("Maximum element in the list is :", max(lst), "\nMinimum element in the list is :",
min(lst))
OUTPUT:
How many numbers: 5
Result:
Thus the python program has been executed and output verified successfully.
Write a python program to display the even and odd elements in a list into two different lists.
AIM:
To write a python program to display the even and odd elements in a list into two different lists.
SOURCE CODE:
a=[]
for i in range(1,n+1):
b=int(input("Enter element:"))
a.append(b)
even=[]
odd=[]
for j in a:
if(j%2==0):
even.append(j)
else:
odd.append(j)
Result:
Thus the python program has been executed and output verified successfully.
Output
Enter element:67
Enter element:43
Enter element:44
Enter element:22
Enter element:455
Write a program to check if a number is present in the list or not. If the number is present, print the
position of the number. Print an appropriate message if the number is not present in the list.
AIM:
SOURCE CODE:
if num in lst :
print(lst.index( num ) )
else :
Result:
Thus the python program has been executed and output verified successfully.
Write a python program to create a list of Tuples with the first element as the number and
second element as the square of the number.
AIM:
To write a python program to create a list of Tuples with the first element as the number and
second element as the square of the number.
SOURCE CODE:
print(a)
Result:
Thus the python program has been executed and output verified successfully.
Output
Write a program to create a nested tuple to store roll number, name and marks of students.
AIM:
To write a program to create a nested tuple to store roll number, name and marks of students.
SOURCE CODE:
tup= ()
while True :
if user == "yes":
print(tup)
break
Result:
Thus the python program has been executed and output verified successfully.
AIM:
SOURCE CODE:
d={'A':1,'B':2,'C':3}
else:
Result:
Thus the python program has been executed and output verified successfully.
Output:
Case 1:
Case 2:
Write a python program to count the frequency of words appearing in a string using a
Dictionary.
AIM:
To write a python program to count the frequency of words appearing in a string using a Dictionary.
SOURCE CODE:
test_string=input("Enter string:")
l=[ ]
l=test_string.split()
wordfreq=[l.count(p) for p in l]
print(dict(zip(l,wordfreq)))
Result:
Thus the python program has been executed and output verified successfully.
Output:
Write a python program to create a dictionary with the roll number, name and marks of n students
in a class and display the names of students who have scored marks above 75.
AIM:
To write a python program to create a dictionary with the roll number, name and marks of n
students in a class and display the names of students who have marks above 75.
SOURCE CODE:
n = int(input("Enter number of students: "))
result = {}
for i in range(n):
print("Enter Details of student No.", i+1)
rno = int(input("Roll No: "))
name = input("Name: ")
marks = int(input("Marks: "))
result[rno] = [name, marks]
print(result)
for student in result:
if result[student][1] > 75:
print(result[student][0],"got marks more than 75")
Result:
Thus the python program has been executed and output verified successfully.
OUTPUT:
Enter number of students: 5
Enter Details of student No. 1
Roll No: 1
Name: Alex
Marks: 90
Enter Details of student No. 2
Roll No: 2
Name: Raj
Marks: 73
Enter Details of student No. 3
Roll No: 3
Name: Nesiga
Marks: 78
Enter Details of student No. 4
Roll No: 4
Name: Arun
Marks: 95
Enter Details of student No. 5
Roll No: 5
Name: Banu
Marks: 66
{1: ['Alex', 90], 2: ['Raj', 73], 3: ['Nesiga', 78], 4: ['Arun', 95], 5: ['Banu', 66]}
Alex got marks more than 75
Nesiga got marks more than 75
Arun got marks more than 75
Write a python program to find the roots of a quadratic equation using math module.
AIM:
To write a python program to find the roots of a quadratic equation using math module.
SOURCE CODE:
import math
a=float(input(“Enter value of a=”))
b=float(input(“Enter value of b=”))
c=float(input(“Enter value of c=”))
r1=(-b+math.sqrt(b*b-4*a*c))/(2*a)
r2=(-b-math.sqrt(b*b-4*a*c))/(2*a)
print(“root1=”, r1)
print(“root1=”, r2)
Output
Result:
Thus the python program has been executed and output verified successfully.
10. PROGRAM USING RANDOM & STATISTICS MODULE
Write a program that generates six random numbers in a sequence created with (start, stop, step).
Then print the mean, median and mode of the generated numbers.
AIM:
To write a python program that generates six random numbers and print the mean,
median and mode of the generated numbers.
SOURCE CODE:
import random
import statistics
a = random.randrange(start,stop,step)
b = random.randrange(start,stop,step)
c = random.randrange(start,stop,step)
d = random.randrange(start,stop,step)
e = random.randrange(start,stop,step)
f = random.randrange(start,stop,step)
Result:
Thus the python program has been executed and output verified successfully.