Cs Practical File Class 11
Cs Practical File Class 11
SCHOOL
KALYANPUR KANPUR
. COMPUTER SCIENCE
PRACTICAL FILE
SUBMITTED TO SUBMITTED
BY HIMANSHU SIR ADITYA VIKRAM SINGH
........................................................OF 11S4
....................................
....................
FLOW OF CONTROL
Ques1 Program that takes a number and
checks whether the given number is odd or even .
num=int(input(“Enter an integer:”))
if num%2==0:
print(num, “is EVEN number.”)
else:
print(num, “is ODD number.”)
OUTPUT
Enter an integer – 8
8 is EVEN number
---------------------------------------------------------------------------------------
-
Ques2 Program to accept three integers and print the largest of
the three. Make use of only if statement.
x=y=z=0
x=float(input(“Enter first number:”))
y=float(input(“Enter second number.”))
z=float(input(“Enter third number.”))
max=x
if y > max :
max=y
if z > max :
max=z
print(“Largest number is”, max)
OUTPUT
Enter first number = 7.235
Enter second number = 6.99
Enter third number = 7.533
Largest number is 7.533
---------------------------------------------------------------------------------------
-
Ques3 Program to test the divisibility of a
number with another number.
OUTPUT
Enter first number = 119
Enter second number = 3
119 is not divisible by 3
===================
Enter first number = 119
Enter second number = 17
119 is divisible by 17
---------------------------------------------------------------------------------------
-
Ques4 Program that reads two number and an arithmetic
operator and displays the computed result .
OUTPUT
Enter first number - 5
Enter second number – 2
Enter operator [ + - * / % ] : *
5.0*2.0 = 10.0
------------------------------------------------------------------------------
OUTPUT
Enter a character – 5
You entered a digit .
---------------------------------------------------------------------------------------
-
a=int(input(“Enter a :”))
b=int(input(“Ener b :”))
c=int(input(“Enter c :”))
if a==0 :
else :
delta = b*b-4*a*c
if delta>0 :
root1=(-b+math.sqrt(delta))/(2*a)
root2=(-b-math.sqrt(delta))/(2*a)
root1= -b/(2*a);
else:
OUTPUT
Enter a : 3
Enter b : 5
Enter c : 2
---------------------------------------------------------------------------------------
LIST MANIPULATION
Ques1 Write a program to createv a copy of list. In the lists copy , add
L2[0] += 10
L2[-1] += 10
OUTPUT
Created copy of the list –[17, 24, 15, 30, 34, 27]
Copy of the list after changes – [27, 24, 15, 30, 34, 37]
Length = len(1st)
uniq = []
dupl = []
count = I = 0
count = 1
if element not in uniq and element not in dupl :
I +=1
If element == 1st[j]
Count +=1
else:
if count ==1:
uniq.append(element)
else:
dupl.append(element)
else:
I +=1
OUTPUT
Element 2 frequency – 3
Element 3 frewquency – 3
Element 4 frequency – 1
Element 5 frequency – 2
Element 6 frequency – 1
Element 7 frequency – 2
Element 1 frequency – 1
Element 9 frequency – 1
---------------------------------------------------------------------------------------
In = len(1st)
mx = max(1st)
ind 1st.index(mx) =
else:
OUTPUT
Enter a list: [6, 8, 11, 6, 12, 7, 16]
---------------------------------------------------------------------------------------
1st1-eval(input("Enter list1:"))
m * 1 = max(1st * 1)
m * 2 = ma(1st * 2)
if mx * 1 >= m * 2
OUTPUT
---------------------------------------------------------------------------------------
number is equal to the sum of the cubes of its digits. Find the
smallest and largest such number from the given list of numbers.
alist = []
s = len(val)
for i in range (s):
csum=0
while num:
dignum % 10
num num // 10
if csum == val[1]:
alist.append(val[1])
OUTPUT
Enter a list :[67, 153, 311, 96, 370, 4050, 371, 955, 407]
---------------------------------------------------------------------------------------
and N. Then create a list from those Ist elements which are
1st * 2 =[]
1st2.append(num)
---------------------------------------------------------------------------------------
STRING MANIPULATION
Ques1 Write a program that inputs a line of text and prints its
the line.
count = 0
print(word)
count += 1
OUTPUT
Python
is
fun.
Total words : 3
---------------------------------------------------------------------------------------
line.
lensub = len(sub)
start count = 0
end = length
while True:
if pos != -1:
count += 1
else:
break
break
Enter line : jingle bells jingle bells jingle all the way Enter substring:
jingle
---------------------------------------------------------------------------------------
decimal number and prints out the decimal part of the number.
8059.
t-s.partition('.')
---------------------------------------------------------------------------------------
school motto and joins them to make a string should also input
day, month and year of your school's foundation date and print
OUTPUT
Enter dd:01
Enter mm:10
---------------------------------------------------------------------------------------
digit or not .
test= False
dig =^8123456789^
for ch in strg:
if ch in dig:
test = True
break
if test False:
OUTPUT
---------------------------------------------------------------------------------------
-
Ques6 Write a program to input an address containing a
pincode and extract and print the pincode from the input
address.
i=0
ln= len(add)
#for ch in add:
while i < 1n
if ch.isdigit():
i +=1
OUTPUT
Enter text:New Delhi, 110001 110001
---------------------------------------------------------------------------------------
TUPLES
if ln % 2 == 1:
mid = mid+1
half = =tup[:mid]
else:
OUTPUT
------------------------------------------------------------------------------
OUTPUT
---------------------------------------------------------------------------------------
following:
Average grade
>=75 A
60-74.999 B
50-59.999 C
<50 D
total = sum(mks)
avg = total /5
grade = 'A'
grade = 'B'
grade = 'C'
else:
grade = 'D'
print("Total Marks: ", total, "Grade:", grade)
OUTPUT
Enter marks tuple: 78.5, 67.8, 89.9, 70.5, 50 Total Marks: 356.70 Grade:
------------------------------------------------------------------------------
them in a tuple. Also, input a name from the user and find if this
1st = []
ntuple tuple(1st)
if mm in ntuple:
else:
OUTPUT
---------------------------------------------------------------------------------------
In = len(tup)
num=tup.count(tup[0])
if num == In:
else:
---------------------------------------------------------------------------------------
as 1st element with 3rd and the 2nd element with the 4th
element.
a,b,c,d=tup
tup = c, d, a, b
------------------------------------------------------------------------------
DICTIONARIES
keys.
rno = []
mks = []
for a in range(4):
mks.append(m)
print(d)
OUTPUT
rno = []
mks = []
Enter Roll No., Marks: 3, 78.4 Enter Roll No., Marks: 4, 70.5
Created dictionary
------------------------------------------------------------------------------
marks of the students of class with roll numbers as the keys and
for a in range(n):
M[r] = m
print("Created dictionary")
print (M)
OUTPUT
Created dictionary
as values.
print (CompWinners)
OUTPUT
How many students ? 5
print("Created dictionary")
print (M)
if rno in M:
del M[rno]
else:
print("Roll no.", rno, "does not exist in dictionary.") print("Final
Dictionary")
OUTPUT
Final Dictionary
---------------------------------------------------------------------------------------
print("Created dictionary")
print(S)
print (S.keys())
OUTPUT
(11: 'siya', 22: 'Ruby', 26: 'Keith', 31: "Preet', 32: "
---------------------------------------------------------------------------------------
selected students
print("Created dictionary")
print(S)
print("Selected roll numbers are:")
print(S.values())
OUTPUT
{11: 'Siya', 22: 'Ruby', 26: 'Keith', 31: 'Preet", 32: "Huna"]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~