CS Practical-11
CS Practical-11
COMPUTER SCIENCE
Grade: XI
PRACTICAL PROGRAM
PROGRAM 1
AIM: Write a program to find Simple Interest
SOURCE CODE:
P= float(input("Enter a Principle Amount: "))
R= float(input("Enter a Rate of Interest: "))
T= float(input("Enter the Time: "))
SI=(P*R*T)/100
print("Principle= ",P,"Rate=",R,"Time=",T)
print("Simple Interest =", SI)
PROGRAM 2
AIM: Write a program to convert Celsius to Fahrenheit.
SOURCE CODE:
c=float(input("Enter temperature in Celsius: "))
f=c*9/5+32
print("Celsius=",c)
print("Temperature in Farenheit is :")
print("F=",f)
PROGRAM 3
AIM: Write a program to display a menu for calculating area of
circle or perimeter of circle.
SOURCE CODE:
r= float(input("Enter the radius:"))
print("1. Area of Circle")
print("2. Perimeter of Circle")
ch=int(input("Enter the choice:"))
if ch==1:
area=3.14*r*r
print("Area of Circle=",area)
elif ch==2:
per=2*3.14*r
print("Perimeter of Circle=",per)
else:
print("Invalid Choice")
PROGRAM 4
AIM: Write a program to find largest of 3 numbers.
SOURCE CODE:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if num1 > num2:
if num1 > num3:
print(num1, "is greater")
else:
print(num3, "is greater")
elif num2 > num3:
print(num2, "is greater")
else:
print(num3, "is greater")
PROGRAM 5
AIM: Write a program to find the factorial of a given number?
SOURCE CODE:
n=int(input("Enter a number: "))
fac=1
i=1
while i<=n:
fac= fac*i
i=i+1
print("Factorial of the number= ",fac)
PROGRAM 6
AIM:Write a program to check whether the number entered is an
Armstrong or not.
SOURCE CODE:
n=int(input("Enter the number"))
s=0
r=0
x=n
while n>0:
r=n%10
s=s+(r*r*r)
n=n//10
if x==s:
print(s,": The number is Armstrong")
else:
print(s,": The number is not Armstrong")
PROGRAM 7
AIM: Write a program to check a number is divisible by another.
SOURCE CODE:
a=int(input("Enter the number: "))
b=int(input("Enter the number: "))
if a % b ==0:
print(a,"is divisible by",b)
else:
print(a,"is not divisible by",b)
PROGRAM 8
AIM:Write a program to find reverse of a given number.
SOURCE CODE:
n=int(input("Enter a value: "))
r=0
rev=0
while n>0:
r=n%10
rev=rev*10+r
n=n//10
print("Reverse=",rev)
PROGRAM 9
AIM: Write a program to print the pattern:
*
**
***
****
*****
SOURCE CODE:
for i in range(1,6):
for j in range(1,i+1):
print('*',end=' ')
print()
PROGRAM 10
AIM: Write a program to print the pattern:
4321
432
43
4
SOURCE CODE:
for i in range(1,5):
for j in range(4,i-1,-1):
print(j,end=' ')
print()
PROGRAM 11
AIM:Write a program that reads a line. Then counts words and
display how many words are in the line.
SOURCE CODE:
s=input("Enter the line: ")
x=s.split()
c=0
for i in x:
c=c+1
print(c)
PROGRAM 12
AIM: Write a program to find minimum element from a list of
element along with its index in the list.
SOURCE CODE:
l=eval(input("Enter the list: "))
length=len(l)
min=l[0]
min_index=0
for i in range(1,length):
if l[i]<min :
min=l[i]
min_index=i
print("Given list is :",l)
print("The minimum element of the given list: ", min)
print("at index",min_index)
PROGRAM 13
AIM: Write a program to find mean of a given list of numbers
SOURCE CODE:
l=eval(input("Enter the list: "))
length=len(l)
mean=sum=0
for i in range(0,length):
sum+=l[i]
mean=sum/length
print("Given list is :",l)
print("The mean of the given list is: ", mean)
PROGRAM 14
AIM: Write a program that takes any two list l and m of the
same size and adds their elements together to form a new list n
whose element are sum of the corresponding elements in l and
m.
SOURCE CODE:
lst1 = eval(input("enter first list = "))
lst2 = eval(input("enter second list = "))
lst3 = [ ]
for i in range(len(lst1)):
lst3 = lst3 + [ lst1 [ i ] + lst2 [ i ] ]
print("new list = ",lst3)
PROGRAM 15
AIM: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.
SOURCE CODE:
lst = eval(input("Enter first list :-"))
num = int(input("Enter the number which you
want to search :-"))
if num in lst :
print(lst.index( num ) )
else :
print("Number not found")
PROGRAM 16
AIM:Write a program that Ask the user to enter a list containing
numbers between 1 and 12 then replace all of the entries in the
list that are greater than 10 with 10.
SOURCE CODE:
for i in range(len(a)) :
if a[i] > 10 :
a[i] = 10