11 Cs Practical Record
11 Cs Practical Record
ROLL NO :
NAME :
CLASS : XI SECTION :
HOUSE :
1
SAINIK SCHOOL AMARAVATHINAGAR
CERTIFICATE
(PM Jigajinni)
PGT in Computer Science
Teacher In-charge
Examiners:
2
TABLE OF CONTENTS
n
2 WAP to compute x for given two integers
x(base) and n (power).
3
SNO DATE PROGRAM NAME PAGE NO SIGNATURE
4
SNO DATE PROGRAM NAME PAGE NO SIGNATURE
5
Experiment - 02
n
WAP to compute x for given two integers x (base) and n (power).
x=int(input("Enter value of base x"))
n=int(input("Enter value of power n"))
result=(x**n)
print(“Result is…”,result)
Output :-
Enter value of base x25
Enter value of power n 2
Result is …625
6
Experiment – 03
WAP to compute simple and compound interest.
p=float(input("Enter the principle amount : "))
t=float(input("Enter time period in years :"))
r=float(input("Enter rate of interest : "))
si=(p*t*r)/100
amt=p * ((1+r/100) ** t)
ci=amt-p
print("Simple interest is…”,si)
print(“Compound interest is…",ci)
Output :-
Enter the principle amount : 5000
Enter time period in years : 2
Enter rate of interest : 5
Simple interest is… 500.0
Compound interest is.. 512.50
7
Experiment – 04
WAP to accept a number from the user and display whether number is
even or odd
x=int(input("Enter number:"))
if (x % 2 == 0) :
print("Given number”, x,”is even")
else:
print("Given number”, x,”is odd")
Output:
Enter number :25
Given number 25 is odd
Enter number: 100
Given number 100 is even
8
Experiment – 05
WAP to input 3 numbers and find the largest.
n1=int(input("Enter number 1 : "))
n2=int(input("Enter number 2 :"))
n3=int(input("Enter number 3 :"))
print(“Given numbers are…”,n1,n2,n3)
if n1 > n2 :
if n1 > n3 :
print("Largest is .....",n1)
else :
print("Largest is .....",n3)
else :
if n2 > n3 :
print("Largest is .....",n2)
else:
print("Largest is .....",n3)
Output:
Enter number 1 : 45
Enter number 2 : 89
Enter number 3 : 59
Given numbers are…45,89,59
Largest is ....89
Enter number 1 :- 89
Enter number 2 :-100
Enter number 3 :-108
Given numbers are… 89,100,108
Largest is ..... 108
9
Experiment – 6
WAP to check whether a given character is an alphabet, digit ,or special
character.
ch=input("Enter a single character : " )
if ch >= "A" and ch <= "Z" :
print("You have entered”,ch,”It is an upper casealphabet")
elif ch >= "a" and ch <= "z" :
print("You have entered”,ch,”It is a lower casealphabet")
elif ch >= "0" and ch <= "9" :
print("You have entered”,ch,”It is a digit")
else:
print("You have entered”,ch,”It is a special character ")
Output :
Enter a single character : M
You have entered M It is an upper case alphabet
10
Experiment – 7
WAP to accept percentage marks of a student and display grade
accordingly.
perc=float(input("Enter percentage of marks of a student"))
if perc >85 :
print("A Grade ")
elif perc > 70 :
print("B Grade ")
elif perc > 60 :
print("C Grade ")
elif perc > 45 :
print("D Grade ")
else :
print("E Grade ")
Output:
Enter percentage of the student89
A Grade
11
Experiment –8
WAP to find the roots of a quadratic equation ax2 + bx + c
import math
d=b*b-4*a*c
if a == 0 :
print("Equation is Linear with only one root ")
root = -c/b
print("Root is ",root)
elif d == 0 :
print("Two roots are real and equal ")
root1=root2=-b/(2*a)
print("Root1=",root1,”andRoot2=",root2)
elif d >0 :
print("Two root are real and unequal")
root1=(-b+math.sqrt(d))/(2 * a)
root2=(-b-math.sqrt(d))/(2 * a)
print("Root1=",root1)
print("Root2=",root2)
else:
print("Two roots are imaginary")
d=-d
real1=real2=-b/(2*a)
imag1=imag2==math.sqrt(d)/(2 * a)
print("Root1=",real1,"+i",imag1)
print("Root2=",real2,"-i",imag2)
12
Output:
Equation is ax2 + bx + c = 0
Enter a:0
Enter b: 2
Enter c: 1
Equation is ax2 + bx + c = 0
Enter a: 1
Enter b: 2
Enter c: 1
Equation is ax2 + bx + c = 0
Enter a : 1
Enter b :9
Enter c :2
Equation is ax2 + bx + c = 0
Enter a : 2
Enter b :4
Enter c :16
13
Experiment –09
WAP to find the factorial of a given number
n=int(input("Enter the Number"))
fact=1
for i in range (1,n+1):
fact=fact * i
print("Factorial of ", n , " is .....",fact)
Output :
Enter the Number5
Factorial of 5 is ..... 120
14
Experiment – 10
WAP to find a given number is prime or composite.
n=int(input("Enter value of n:"))
flag=0
if n==0 or n == 1:
print("Neither prime nor composite number")
else:
for i in range (2,n) :
if n % i == 0 :
flag+= 1
break
if flag == 0 :
print("Given number is prime number")
else:
print("Given number is composite number")
Output :
15
Experiment – 11
WAP to print Fibonacci series up to certain limit N.
n=int(input("Enter Value of n : "))
f1=0
f2=1
if n <=1 :
print("Invaild Series")
else:
print(“Fibonacci Series is……”)
print(f1,f2,end=" ")
for i in range(2,n):
f3=f1 + f2
print(f3,end=" " )
f1=f2
f2=f3
Output :
Enter Value of n : 0
Invalid series
Enter Value of n :1
Invalid series
16
Experiment – 12
WAP to accept a number and display whether it is a perfect number or
not.
n=int(input("Enter value of n:"))
sum=0
for i in range (1,n):
if n % i == 0 :
sum = sum + i
if sum == n :
print("Given number",n,"is perfect number")
else:
print ("Given number",n,"is not perfect number")
Output:
Enter value of n: 5
Given number 5 is not perfect number
Enter value of n : 6
Given number 6 is perfect number
17
Experiment – 13
WAP to accept a number and display whether it is a palindrome
number or not.
num=int(input("Enter any multidigit number"))
rev=0
num1 =num
while num >0 :
rem = num % 10
rev = rev * 10 + rem
num= num // 10
if num1 == rev :
print("Given multidigit number", num1 ," is palindrome")
else:
print("Given multidigit number",num1 , " is not apalindrome ")
Output:
Enter any multidigit number56
Given multidigit number 56 is not a palindrome
18
Experiment – 14
# program to compute the reserve of given number.
n=int(input("Enter tha multidigit number :- "))
m=n
rev=0
while n >0 :
rem = n % 10
rev = rev * 10 + rem
n = n // 10
print(" /n Reverse of " ,m , " is " , rev)
Output :
Enter tha multidigit number :- 25
/n Reverse of 25 is 52
19
Experiment – 15
# program to find the given number is Armstrong number or not.
num=int(input("Enter 3 digit number"))
sum = 0
f = sum
while f >0 :
a = f % 10
sum += sum ** 3
if sum == num :
print(" It is a Armstrong number",num)
else:
print(" It is a Not Armstrong number ",num)
Output :
20
Experiment – 16
# program to display prime number up to a certain limit.
lower=int(input("Enter lower range " ))
upper=int(input("Enter upper range " ))
if lower > upper :
print("Invail number ")
else :
for num in range (lower ,upper + 1 ) :
if num >1 :
for i in range (2 , num):
if num % i == 0 :
break
else :
print(num ,"is prime number")
Output :-
Enter lower range 10
Enter upper range 50
11 is prime number
13 is prime number
17 is prime number
19 is prime number
23 is prime number
29 is prime number
31 is prime number
37 is prime number
41 is prime number
43 is prime number
47 is prime number
21
Experiment – 17
# program to print the pattern.
n=int(input("Enter the value of n "))
for i in range (1, n + 1 ) :
for j in range(1,i +1 ) :
print(j, end= " " )
print()
output :-
Enter the value of n 5
1
12
123
1234
12345
22
Experiment – 18
Output :-
Enter value of x : 1
Enter limit:2
After term 1 is 0
After term 2 is 1.0
After term 3 is 2.5
sum of given series is ... 2.5
23
Experiment – 19
WAP to compute the greatest Common Divisor and Least Common
Multiple of two integers
m=int(input("Enter integer value:-"))
n=int(input("Enter integer value:-"))
a,b=m,n
if m <n :
m,n=n,m
rem=m%n
while rem!=0 :
m,n=n,rem
rem=m%n
print("GCD of",a,"and",b,"is=",n)
LCM=(a*b)/n
print("LCM of",a,"and",b,"is=",LCM)
Output :-
Enter integer value2
Enter integer value5
GCD of 2 and 5 is= 1
LCM of 2 and 5 is= 10.0
>>>
24
Experiment – 20
# program to check the whether string is a palindrome or not.
string=input("Enter stirng")
rev_string = string[: : -1]
if string==rev_string :
print("string is palindrome")
else :
print("string is not palindrome")
Output:-
Enter stirng1221
string is palindrome
Enter stirnggadag
string is palindrome
25
Experiment – 21
# WAP that counts the number of alphabet, digits, uppercase letters,
# lower case letter, spaces Vowels, Consonants and other characters in
# the string entered
str1=input("Enter a string")
NA=ND=NU=NL=NS=NV=NC=NO=0
for ch in str1:
if ch.isalpha () :
NA+=1
if ch.isupper () :
NU+=1
if ch=="A" or ch=="E" or ch=="I" or ch=="o" or ch=="u" :
NV+=1
else:
NC+=1
if ch.islower () :
NL+=1
if ch=="a" or ch=="e" or ch=="i" or ch=="o" or
ch=="u" :
NV+=1
else:
NC+=1
elif ch.isdigit () :
ND+=1
elif ch.isspace () :
NS+=1
else:
NO+=1
print("NO of Alphabet=",NA)
26
print("NO of Upper case letters=",NU,"and Lower Case Letters=",NL)
print("NO of Digits=",ND)
print("NO of Spaces=",NS)
print("NO of Vowels=",NV,"and NO of Consonants=",NC)
print("NO of other Characters=",NO)
Output :-
Enter a string :My name is name and my roll number is 1111 and my
house is house and email is email@!@$%^.com
NO of Alphabet= 64
NO of Upper case letters= 1 and Lower Case Letters= 63
NO of Digits= 4
NO of Spaces= 18
NO of Vowels= 27 and NO of Consonants= 37
NO of other Characters= 7
27
Experiment – 22
# program to display maximum and minimum elements of a given list.
L=eval(input("Enter a list"))
max=L[0]
for i in range(0,len(L)) :
if L[i] >max :
max=L[i]
print("Maximum of the given list is :",max)
min=L[0]
for i in range(0,len(L)):
if L[i] <min :
min=L[i]
print("Minimum of the given listis ",min)
Output :-
Enter a list :12,56,25,45,1,89,78,5
Maximum of the given list is : 89
Minimum of the given listis 1
Enter a list2,56,25,45,1,98,78,5,0
Maximum of the given list is : 98
Minimum of the given listis 0
28
Experiment – 23
# WAP to accept a string(a sentence) and returns a string having first
# letter of each word in capital letter.
Output :-
Enter a string :my name is raj
original string my name is raj
My Name Is Raj
29
Experiment – 24
# WAP in Python to display those strings which are string with ‘A’ of
# given list.
L=["AUSHIM","LEENA","AKHTAR","HIBA","NISHANT","AMAR"]
count=0
for i in L :
if i[0] in ("aA") :
count+=1
print (i)
print("Appearing ",count,"times")
OUTPUT :-
AUSHIM
AKHTAR
AMAR
Appearing 3 times
30
Experiment – 25
WAP to input list of elements and swap the elements in even location
with odd location.
L=[8,23,54,11,99,71,21,55,60,2]
print("The Given list is ",L)
L1=L
print("List before shifting",L1)
for i in range(len(L1)-1):
L1[i],L[i+1]=L1[i+1],L1[i]
print("List after shifting",L1)
OUTPUT :-
The Given list is [8, 23, 54, 11, 99, 71, 21, 55, 60, 2]
List before shifting [8, 23, 54, 11, 99, 71, 21, 55, 60, 2]
List after shifting [23, 54, 11, 99, 71, 21, 55, 60, 2, 8]
31
Experiment – 26
WAP to find and display cumulative sum of elements in a given list.
list=[1,3,5,7,8]
finallist=[list[0]]
for i in range(1,len(list)):
finallist+=[finallist[i-1]+list[i]]
print(finallist)
OUTPUT :-
[1]
[1, 4]
[1, 4, 9]
[1, 4, 9, 16]
[1, 4, 9, 16, 24]
32
Experiment – 27
L=[3,21,5,6,3,8,21,6]
L1=[ ]
L2=[ ]
for i in L :
if i not in L2 :
x=L.count (i)
L1.append (x)
L2.append (i)
print("Element "," \t\t\t ", " frequency")
for i in range(len(L1)) :
print(L2[ i ] , " \t\t\t " , L1[ i ])
OUTPUT :-
Element frequency
3 2
21 2
5 1
6 2
8 1
33
Experiment – 28
#program to find & display the sum of all the elements ending with 3 in a given list.
L=[33,13,92,99,3,12]
sum=0
x=len(L)
for i in range (0,x) :
if type (L[i])== int :
if L [i] %10==3 :
sum+= L [ i ]
print ("sum of the elements ending with 3 is ...",sum)
OUTPUT :-
33
13
3
sum of the elements ending with 3 is ... 49
34
Experiment – 29
WAP to shift the negative number to left and the positive numbers to
right in a given list
L=[-12,11,-13,-5,6,-3,-6]
n=len(L)
print("original list:",L)
for i in range(n-1):
for j in range(n-i-1):
if L[ j ]<0 :
L[ j ] , L[ j+1] = L[ j + 1] , L[ j ]
print("After shifting list is : " , L )
OUTPUT :-
original list: [-12, 11, -13, -5, 6, -3, -6]
After shifting list is : [11, 6, -6, -3, -5, -13, -12]
35
Experiment – 30
WAP to accept values from user and create a tuple.
t=tuple()
n=int(input("Enter any number : "))
for i in range(n):
a=input("Enter number :" )
t=t+(a,)
print("output is ")
print(t)
OUTPUT:-
Enter any number : 5
Enter number :56
Enter number :58
Enter number :45
Enter number :52
Enter number :12
output is
('56', '58', '45', '52', '12')
36
Experiment – 31
# program to input tuple of elements and search for a given elements in the
tuple.
t=tuple()
n=int(input("Enter number of elements in a tuple"))
for i in range(n) :
ele=int(input("Enter the elements in a tuple"))
t=t+(ele,)
print("Given tuple is ......",t)
x=int(input("Enter the elements to be searched "))
for i in range (n):
if t[i] == x :
print("Elements ", x ,"is found at ",i+1 ,"position ")
break
else:
print("Sorry !The given elements ",x, "is not found in the
tuple ")
OUTPUT :
OUTPUT :-
38
Experiment – 33
n=int(input("How many students ?" ))
stud={ }
for i in range(1,n+1) :
print("Enter details of students",i)
rollno=int(input("Roll no:"))
name=input("Name:")
marks=float(input("Marks:"))
d={"Roll_no":rollno,"Name":name,"Marks":mark}
key="stud"+str(i)
stud[key]=d
print("Students with marks >75 are:")
for i in range(1,n+1):
key="stud"+str(i)
if stud[key] ["Marks"] >=75 :
print(stud[key])
OUTPUT :-
How many students ? 2
Enter details of students 1
Roll no:1234
Name:sdsf
Marks:100
Enter details of students 2
Roll no:5678
Name:dfgh
Marks:74
Students with marks >75 are:
{'Roll_no': 1234, 'Name': 'sdsf', 'Marks': 100.0}
39
Experiment – 34
WAP to find standard deviation and Variance of a tuple of numeric values
import math
import statistics
t=(10,25,45,42,39)
n=len(t)
total=0
for i in range(n):
total=total+(t[i]-statistics.mean(t))**2
SD=math.sqrt(total)/(n-1)
print("standard deviation",SD)
var=SD**2
print("variation",var)
OUTPUT:-
standard deviation 7.292119033586877
variation 53.175000000000004
40
Experiment – 35
WAP to generate Random Number within a given range & store in a list.
import random
start=int(input("Enter starting Range Value:"))
end=int(input("Enter ending Rangevalue:"))
num=int(input("Enter number of random numbers to be generated:"))
L=[ ]
for i in range (num) :
L.append(random.randint(start,end))
print("The list of random numbers generated
within a given range:")
print(L)
OUTPUT :-
Enter starting Range Value:10
Enter ending Rangevalue:100
Enter number of random numbers to be generated:20
The list of random numbers generated within a given range:
[45, 41, 75, 82, 66, 92, 48, 47, 73, 75, 65, 99, 86, 63, 12, 92, 94, 88, 88, 67]
41
Experiment – 36
WAP to count the frequency of words in a sentence using a dictionary.
OUTPUT :-
Enter Sentence: my name is name and my class is class and house is house
house my name is name and my class is class and house is house house
Count frequencies of words in given sentence
{'my': 2, 'name': 2, 'is': 3, 'and': 2, 'class': 2, 'house':3}
42