You are on page 1of 22

3

Computer science
Practical File

Submitted by:

Acknowledgment
I would like to express my special thanks of
gratitude to my CS Teacher Ms.Sapna ma’am
For their able guidance and support in
completing my project file.

I would also like to extend my gratitude to our


Principal Rev.Sr Sheeba for providing me with
all the facility that was required.

Date: Name:

Q1)WAP to find the largest number among the three


inputted numbers.
Solution:
A=int(input(“Enter first number:”))
B=int(input(“Enter second number:”))
C=int(input(“Enter third number:”))
if (A>B):
if (A>C):
print(A,”is the largest number”)
else:
if (B>C)
print(B,”is the largest number”)
else:
print(C,”is the largest number”)

Q2)WAP to perform the following task according to the


user’s choice using menu.
(a) Area of Circle
(b) Area of Rectangle
(c) Circumference of Circle
(d) Area of Square
Solution:
while True:
print(“1,For Area of Circle”)
print(“2,For Area of Rectangle”)
print(“3,Circumference of Circle”)
print(“4,For Area of Square”)
ch=int(input(“Enter your choice(enter 0 to exit):”))
if ch==1:
r=int(input(“Enter the radius of the Circle:”))
a=3.14*r*r
print(“Area of Circle:”,a)
elif ch==2 :
l=int(input(“Enter the length:”))
b=int(input(“Enter the breadth:”))
a=l*b
print(“Area of Rectangle:”,a)
elif ch==3:
r=int(input(“Enter the radius of the Circle
:”))
c=2*(int(3.14*r))
print(“Circumference of Circle:”,c)
elif ch==4:
l=int(input(“Enter the side of square:”))
a= 1*1
print(Area of Square:”,a)
elif ch==0:
break
else:
print(“Invalid Option”)

Q3)WAP to accept a number,find out and display


whether it is an Armstrong number or not.
Note:An Armstrong number of three digits is an integer
such that the sum of the cubes of its digits os equal to
number itself.For example,371 is an Armstrong number
since3**3+7**3+1**3=371
Solution:
num=int(input(“Enter 3-digit number:”))
f=num
sum=0
while(f>0):
a=f%10
f=int(f/10)
sum=sum+(a**3)
if (sum==num):
print(num,”is a Armstrong number.”)
else:
print(num,”is not an Armstrong number.”)

Q4)Write a program to accept a number and display


whether the number is a Palindrome or not.
Solution:
orig=int(input(“Enter the number:”))
num=orig
rev=0
while num>0:
digit=num%10
rev=rev*10+digit
num=int(num/10)
if orig==rev:
print(‘Palindrome’)
else:
print(‘Not a Palindrome’)

Q5)WAP to print the following pattern:


A
BC
DEF
GHIJ
KLMNO
Solution:
i=1
num=65
while i<=5:
j=1
while j<=1:
print(chr(num),end=” “ )
j=j+1
num=num+1
print()
i=i+1

Q6)WAP to print the following patterns:


(i)1
12
123
1234
12345
Solution:
(i) n=5
for i in range (1,n+1):
For j in range(1,i+1):
print(j,end=’ ‘)
print(“ “)

Q7)Write a program that reads a line,then counts how


many times a substring “is” appears in the line and
displays the count.
Solution:
str1=input(“Enter line:”)
str2=”is”
L=str1.split()
cnt=0
for i in L:
if i==str2:
cnt+=1
Print(“Substring is appearing:”,cnt)

Q8)Write a program to remove vowels from a string.


Solution:
str1=input(“Enter string:”)
str2=” “
for i in range(len(str1)):
if str1[i] not in “ieouaAOIUE”:
str2= str2+str1[i]
print(“Original string:”,str1)
print(“Resultant string:”,str2)

Q9)WAP that takes a list’L’ as an argument,adds 5 in


all the odd values and 10 in all the even values of the
list L.Also display the list.
Input:L=[10,20,3,100,65,87,1]
Output:[20,30,8,110,70,92,12]
Solution:
L=[10,20,3,100,65,87,2]
for i in range (len(L)):
if type(L[i])==int:
if L[i]%2==0:
L[i]=L[i]+10
else:
L[i]=L[i]+5
print(L)

Q10)WAP to display unique and duplicate items of a


given list into two different lists.
Input:L1=[2,7,1,4,9,5,1,4,3]
Output:[2,7,1,4,9,5,3]
[1,4]
Solution:
L1=[2,7,1,4,9,5,1,4,3]
L2=()
L3=()
for i in L1:
if i not in L2:
L2.append(i)
else:
L3.append(i)
print(L2)
print(L3)

Q11)WAP to exchange first-half elements of list with


second-half elements assuming list is having even
number of elements.
Solution:
L=[10,20,30,40,50,60,70]
x=int(len(L)/2)
for i in range (x):
L[i],L[x+i]=L[x+i],L[i]
print(L)
Q12)A list Num contains the following elements:
3,21,5,6,14,8,14,3
WAP to swap the content with the next value divisible
by 7 so that the resultant list looks like:
3,5,21,6,8,14,3,14
Solution:
num=[3,21,5,6,14,8,14,3]
L=len(num)
i=0
while i<L:
if num[i]%7==0:
num[i],num[i+1]=num[i+1],num[i]
i=i+2
else:
i=i+1
print(num)

Q13)Write a Python program to input ‘n’ names and


phone numbers to store it in a dictionary and print the
phone number of a particular name.
Solution:
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
1=phone.keys()
x=input(“Enter name to be searched:”)
for i in 1:
if i==x:
print(x,”:phone no is:”, phone[i])
break
else:
print(x,”does not exist”)
Q14)Write a Python program to input any values for
two tuples.Print it,interchange it,and then compare
them.
Solution:
t1=()
N1=int(input(“Enterthe number of elements in the first
tuple:”))
for i in range(n1):
el=eval(input(“Enter the element:”))
t1+=(el,)
print(t1)
n2=int(input(“Enter the elements in the second tuple:”))
for i in range(n2):
el=eval(input(“Enter the element:”))
t2+=(el,)
print(t2)
t1,t2=t2,t1
if t1>t2:
print(“The first tuple is greater than the second
tuple:”)
elif t1<t2:
print(“The first tuple is smaller than the second
tuple:”)
elif t1==t2:
print(“Both the tuples are equal:”)
else:
print(“Invalid!”)
Q15)Write a Python program to input names of ‘n’
employees and their salary details like basic
salary,house rent and conveyance allowance .Calculate
total salary of each employee and display.
Solution:
d=dict()
n=int(input(“Enter the number of entries:”))
for i in range(n):
name=input(“Enter the name of employees:”)
b=int(input(“Enter the basic salary:”))
h=int(input(“Enter the house rent allowance:”))
c=int(input(“Enter the conveyance allowance:”))
d[name]=[b,h,c]
print()
print(“Name”,”\t\t”,”Net Salary”)
for i in d:
s=0
for j in d[i]:
s+=j
print(i,”\t\t”,s)
Q16)Write a program to accept a character from the user and
display whether it is a vowel or consonant.
Solution:
c=str(input(“Enter a character:”))
If c==”a”or c==”A”or c==”e”or c==”E”or c==”u”or c==”U”:
Print(‘”’+c+’”’,”is a consonant.”)

You might also like