[go: up one dir, main page]

0% found this document useful (0 votes)
2 views16 pages

Final Practical Cs 2025

The document contains a series of practical programming exercises including line search, list manipulation, sorting algorithms (bubble sort and insertion sort), and data storage using tuples and dictionaries. Each practical exercise is accompanied by Python code that demonstrates the required functionality, such as finding maximum and minimum values in a list, counting character occurrences in a string, and calculating the area and circumference of a circle. The exercises cover a range of topics suitable for learning basic programming concepts and data structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

Final Practical Cs 2025

The document contains a series of practical programming exercises including line search, list manipulation, sorting algorithms (bubble sort and insertion sort), and data storage using tuples and dictionaries. Each practical exercise is accompanied by Python code that demonstrates the required functionality, such as finding maximum and minimum values in a list, counting character occurrences in a string, and calculating the area and circumference of a circle. The exercises cover a range of topics suitable for learning basic programming concepts and data structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Practical: -1

Q.1: - perform a line search

CODE: -
11= eval (input ("enter the list elements: "))
length = Len (11)
element = int (input ("enter the element to be searched for: "))
for i in range (0, length):
if element == 11[i]:
print (element, found at index',i)
break
else:
print (element, 'not present in the given list')

z
Practical:-2

Q:-2 WPA to split original list into two separate list

Code: -

WTemp = ['Mon', 45, 'Tue', 43, 'Wed', 42, 'Thu', 40, 'Fri', 38, 'Sat', 40, 'Sun',38]
ln=len (WTemp)
Days = []
Degrees = []
for i in range (ln):
if (i % 2) == 0:
Days. Append (WTemp[i])
else:
Degrees.append (WTemp[i])
print ("Original list is: ", WTemp)
print ("The days are: ", Days)
print ("The temperatures are: ", Degrees)

Practical: -3
Q: -3 BUBBLE SORT

Code: -
def main ():
def main ():
l= [42,29,74,11,65,58,]
n=Len(l)
print ('original list is:',l)

for i in range(n-1):
for j in range (n-1-i):
if l[j]> l[j+1]:
l[j], l[j+1] =l[j+1], l[j]
print ("list after sorting is: ",l)
main ()

Practical: -4
Q: -4 INSERTION SORT
CODE:-.

Practical: -5
Q: -5 FIND THE HIGHEST AND LOWEST NUMBER IN A USER INPUT
LIST

Code: -
lst=[]
Num=int (input ("how many numbers: "))
for n in range (Num):
Num =int (input ('enter number; ‘))
lst.append(num)
print ('maximum element in the list is: ‘, max(lst))
print ('minimum element in the list is: ‘, min(lst))

Practical:6
Q: -6 WPA TO STORE RECORD OF STUDENTS IN TUPLE AND PRINT
THEM

CODE: -
st=((200, "Harmeet", 88), (201, "Deepika", 98), (202, "Radhika", 78), (204,
"Shaurya", 90))
print ("S_No"," Roll No"," Name"," Marks")
for i in range (0, len (st)):
print((1+1),'\t',st[i][0],'\t',st[i][1],'\t',st[i][2])

Practical: -7
Q: -7 WPA TO INPUT ANY TWO TUPLES AND SWAP THEIR
VALUES

CODE: -

Practical: - 8
Q: -8 WPA TO ENTER NAMES OF EMPLOYEES AND THEIR SALARIES
AS INPUT AND
STORE THEM IN A DICTIONARY

CODE: -

num = int (input ("Enter the number of employees whose data to be stored salary: "))
count = 1
employee = dict()
while count <= num:
name = input ("Enter the name of the Employee: ")
salary = int (input ("Enter the salary: "))
employee [name] = salary
count += 1
print("\n\nEMPLOYEE_NAME\tSALARY")
fork in employee:
print (k, '\t\t',employee[k])

Practical: -9
Q: -9 WPA A PROGRAM TO COUNT THE NUMBER OF TIMES A
CHARACTER APPER IN
GIVEN STRING USING A DICTONARY

CODE: -
str = input ("Enter a string: ")
dict1= {}
for ch in str:
if ch in dict1:
dict1[ch]+=1
else:
dict1[ch]=1
for key in dict1:
print(key,':’, dict1[key])

Practical: -10
Q:-10 WAP FOR REVERSING A TUPLE

Code: -
tup= (10,20,30,40,50)
print ("original tuple is ")
for i in range (0, len(tup)):
print(tup[i])
print ("tuple in reverse”)
for j in range (len(tup)-1, -1, -1):
print(tup[j])

Practical: -11
Q: -11 WAP PROGRAM TO INPUT ‘N’ NAMES AND PHONE NO TO
STORE IT IN A
SICTIONARY AND PRINT THE PH. NO. OF A PATICULAR
NAME

CODE: -
phone=dict()
i=1
n=int (input("Enter number of entries:"))
while i<=n:
a=input ("Enter Name:")
b=input ("Enter Phone no:")
phone [a]=b
i = i+1
l = phone.keys()
x=input ("Enter name to be searched:")
for i in l:
if i==x:
print (x,": phone no is:",phone[i])
break
else:
print (x, "does not exist")
Practical: -12

Q: -12 WAP TO INPUT FRIENDS NAME, PHONE NO. PERFORM


OPERATIONS

CODE: -
Practical: -13

Q: - 13 CIRCLE MODULE

Code: -

import math
def area(radius):
return int (math.pi* radius*radius)
def circumference(radius):
return int (math.pi * 2 * radius)
r=5
print ("Area of circle is:", area(r))
print ("Area of circumfrence is:", circumference(r))
Practical: -14

Q:- 14 WAP THAT FILLS A LIST WITH NUMBER USING(RAND.INT)

Code: -
from random import randint
def fill_list(lst, limit, low,high):
for i in range(limit):
lst.append(randint(low,high))
minimum = int (input ("Min: "))
maximum = int (input ("Max: "))
n = int (input ("Numbers limit: "))
a= []
fill_list(a,n,minimum,maximum)
print(a)
Practical: -15

Q: -15 WAP USINGA USER-DEFINED FUNCTION CAL_MEAN [] TO


CALCULATE THE
MEAN OF FLOATING VALUES STORE IA A LIST

CODE: -
def cal_Mean(list1):
total = 0
count = 0
for i in list1:
total += i
count += 1
mean = total / count
print ("The calculated mean is:", mean)
list1 = [2.6,3.4,8.5,7.9]
cal_Mean(list1)

You might also like