0% found this document useful (0 votes)
10 views38 pages

Computer Science

The document contains a collection of Python programs organized into categories such as Sequential, Selection Based, Loop Based, List Based, and Dictionary Programs. Each section includes various coding exercises, such as calculating squares and cubes, determining areas and perimeters, checking eligibility to vote, and manipulating lists and dictionaries. The programs demonstrate fundamental programming concepts and provide outputs for user inputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views38 pages

Computer Science

The document contains a collection of Python programs organized into categories such as Sequential, Selection Based, Loop Based, List Based, and Dictionary Programs. Each section includes various coding exercises, such as calculating squares and cubes, determining areas and perimeters, checking eligibility to vote, and manipulating lists and dictionaries. The programs demonstrate fundamental programming concepts and provide outputs for user inputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer

Science
Practical File

Christina Pinto
Roll no : 08
11 A
Sequential
Programs
#1. Write a program to read any
number and print its square and cube
num1 = float(input('Enter Number:'))
square = num1**2
cube = num1**3
print('The Square of the number is:', square)
print('The Cube of the number is:', cube)

Output
#2. Write a Program to read the length and
breadth of a rectangle and calculate its Area
and Perimeter.
length = float(input('Enter Length of the
Rectangle:'))
breadth = float(input('Enter Breadth of the
Rectangle:'))
Area = length*breadth
Perimeter = 2*(length + breadth)
print('The Area of the rectangle is', Area)
print('The Perimeter of the rectangle is ',
Perimeter)

Output
#3. Write a program for basic calculations
Num1 = int(input('Enter First Number:'))
Num2 = int(input('Enter Second Number:'))
Sum = Num1 + Num2
Diff = Num1 - Num2
Prod = Num1*Num2
Quot = Num1/Num2
print(Num1 ,'+', Num2, '=', Sum)
print(Num1 ,'-', Num2, '=', Diff)
print(Num1 ,'*', Num2, '=', Prod)
print(Num1, '/', Num2, '=', Quot)

Output
#4. Write a program to calculate EMI for the
Amount, Period that is input.

Amt = float(input('Enter Loan Amount:'))


Prd = float(input('Enter Period of Time in number
of years:'))
EMI = Amt/(12*Prd)
print('The EMI is:',EMI)

Output
#5. Write a program to compute x^n, for the
two integers x and n.
x = int(input('Enter the Number Required:'))
n = int(input('Enter the Power to which the
number should be raised:'))
ans = x**n
print('The Answer is', ans)

Output
Selection Based
Programs
#1. Write a menu based program to read the
user choice for the operations below:
print('Menu')
print('[Link] of the Rectangle')
print('[Link] of the Square')
print('[Link] of the Circle')
choice = int(input('Enter your choice (1-3):'))
if choice == 1:
l = float(input('Enter length of the rectangle:'))
b = float(input('Enter breadth of the rectangle:'))
a_r = l*b
print('The Area of the Rectangle is:', a_r)

elif choice == 2:
s = float(input('Enter side of the square:'))
a_s = s*s
print('The Area of the Square is:', a_s)

elif choice == 3:
r = float(input('Enter the radius of the circle:'))
a_c = 2*3.14*r
print('The Area of the Circle is:', a_c)

else:
print('Invalid Input')
Output
#2. Write a Program to read marks scored in
Computer Science and print the grade

Mark = float(input('Enter Marks received:'))

if Mark >= 90 and Mark <= 100:


print('Grade obtained: A')
elif Mark >= 70 and Mark <= 89:
print('Grade obtained: B')
elif Mark >= 33 and Mark <= 69:
print('Grade obtained: C')
elif Mark >= 0 and Mark <= 33:
print('Grade obtained: E')
else:
print('Invalid Input')
Output
#3. WAP to find biggest of three numbers.
num1 = float(input('Enter first number:'))
num2 = float(input('Enter second number:'))
num3 = float(input('Enter third number:'))

if num1 > num2 and num1 > num3:


print(num1,'is the greatest number')
elif num2 > num1 and num2 > num3:
print(num2,'is the greatest number')
elif num3 > num1 and num3 > num2:
print(num3,'is the greatest number')
elif num1 == num2 and num2> num3:
print(num1,'is the greatest number')
elif num2 == num3 and num2 > num1:
print(num2,'is the greatest number')
elif num1 == num3 and num1 > num2:
print(num1, 'is the greatest number')
else:
print('The numbers are equal')
Output
#4. Write a program to check whether the person
is eligible to vote.
age = int(input('Enter age:'))
if age >= 18 and age <= 100:
print('The person is eligible to vote')
elif age < 18 and age >= 0:
print('The person is not eligible to vote')
else:
print('Invalid Input')

Output
#5. Write a program to find whether a number
is odd or even
num1 = int(input('Enter number:'))
if num1%2 == 0:
print(num1, 'is an even number')
else:
print(num1, 'is an odd number')

Output
#6. Write a program to check whether a number
is divisible by 5
num1 = float(input('Enter required number:'))
if num1%5 == 0:
print('The number is divisble by 5')
else:
print('The number is not divisble by 5')

Output
#7. Write a program to find profit and loss

num1 = float(input('Enter required number:'))


if num1%5 == 0:
print('The number is divisble by 5')
else:
print('The number is not divisble by 5')

Output
#[Link] a Program to input any number
between 1 to 7 and print the weekday, assume 1
as Sunday.
if num == 1:
print('The day is Sunday')
elif num == 2:
print('The day is Monday')
elif num == 3:
print('The day is Tuesday')
elif num == 4:
print('The day is Wednesday')
elif num == 5:
print('The day is Thursday')
elif num == 6:
print('The day is Friday')
elif num == 7:
print('The day is Saturday')
else:
print('Invalid Input')
Output
#9. Write a program to read two numbers and
print the the diff reducing the smaller no
from the higher

num1 = float(input('Enter the first number:'))


num2 = float (input('Enter the second number:'))

if num1>num2:
print(num1, 'is greater by', num1 - num2)
elif num2>num1:
print(num2, 'is greater by', num2 - num1)
else:
print('The difference is 0')

Output
#10. Write a program to find the highest of
three numbers.
num1 = float(input('Enter the first number:'))
num2 = float(input('Enter the second number:'))
num3 = float(input('Enter the third number:'))
if num1 > num2 and num1 > num3:
print (num1, 'is the greatest number')
elif num2 > num1 and num2 > num3:
print (num2, 'is the greatest number')
else:
print (num3,'is the greatest number')

Output
Loop Based
Programs
#1. Write a program to print factors of a
number
n = int(input('Enter number:'))

print('The factors of', n,'are:')


for i in range(1,n+1,1):
if n%i == 0:
print(i)

Output
#2. Write a program to print factorial of a
number.
n = int(input('Enter number:'))

i = 1
pdt = 1
while i <= n:
pdt = pdt*i
i += 1
print(n,'Factorial is:', pdt)

Output
#3. Write a program to print pattern

for i in range (1,4):


for j in range (1, i +1):
print(j, end =' ')
print()

Output
#4. Write a program to print pattern

for i in range (1,4):


for j in range (1, i +1):
print(chr(64+i), end =' ')
print()

Output
#5. Write a program to print pattern

for i in range (1,4):


for j in range (1, i +1):
print('*', end =' ')
print()

Output
List Based
Programs
#1. Write a program to swap contents
l = [13, 25, 17 , 15, 19, 10 ,3 ,35]

i = 0
while i < 7:
if l[i]%5 != 0:
i+=1

elif l[i]%5 == 0:
l[i], l[i+1] = l[i+1], l[i]
i+=2

print(l)

Output
#2. Write a program to display unique and duplicate
values
L=[2,3,4,2,3,6]
ul = []
dl = []

for i in L:
if [Link](i) == 1:
[Link](i)

elif [Link](i) != 1:
if i not in dl:
[Link](i)

print('Unique List:', ul)


print('Duplicate List:', dl)

Output
#3. Write a program to display element position
l1 = [1,2,3,4,5,6,7,8,9,10]
print(l1)

el = int(input('Enter element: '))


for i in l1:
if i == el:
print([Link](i)+1)

if el not in l1:
print('Not found')

Output
#4. Write a program to show places with more than 5
characters
l = ["DELHI","LONDON","PARIS","NEW YORK","DUBAI"]

print(l)

for i in l:
if len(i) > 5:
print(i)

Output
#5. Write a program to square the integers
Display the square of an element if it is an integer and update the list.
INPUT : [2,'Anu',4,'Raji','Rakhi']
OUTPUT: [4,'Anu',16,'Raji','Rakhi']

l = [2,'Anu',4,'Raji','Rakhi']

for i in range(len(l)):
if type(l[i]) == int:
l[i] = (l[i]**2)

print(l)

Output
Dictionary
Programs
#1. Write a program to ADD EMPLOYEES AND SALARY
d = {}
i = 1
while i < 2:
name = input('Enter the name of the Employee:
')
sal = float(input('Enter the salary: '))
d[name] = sal
k = input('Do you want to add another
employee? yes/no: ')
if k != 'yes':
print(d)
break

Output
#2. Write a program to ADD EMPLOYEES AND SALARY
l=[2,3,4,2,3,5,3,5]
d ={}
for i in l:
d[i] = [Link](i)

for k in d:
print('freq of', k, 'is', d[k])

Output

You might also like