You are on page 1of 28

Computer

Science
Practical
File
Name – Bani Galhotra
Class – XIIth – B
Roll No. – N07B
Submitted to – Mr. Anish Sir

Internal Signature External Signature


Index
Sr No. Topic (Python)

1 Enter special character in a normal string

2 Enter two integers and perform all arithmetic operations

3 Find weather an input number is perfect or not

4 Find factorial of the entered number

5 Calculate the sum of series: 11 /1 + 22 /2 + 33 /3 + … + nn /n

6 Calculate the simple interest in a bank deposit

7 Calculating the Area of a square, rectangle, circle

8 Calculating the Total surface area, Lateral surface area of a


cube
9 Calculating the Total surface area, Lateral surface area of a
cylinder
10 Calculating the Total surface area, Lateral surface area of a
cubiod
11 Calculating the Total surface area, Lateral surface area of a
cone
12 Calculating the volume of a cube, cuboid, cylinder, cone, sphere

13 Calculating the Total surface area of a sphere

14 Calculating the Total surface area, Lateral surface area of a


hemisphere
15 Find weather input number is prime or composite

16 Calculate the sum of squares of first n natural numbers

17 Calculate the sum of cubes of first n natural numbers

18 Find the biggest and smallest of given 4 numbers

19 Number Guessing Game between 1 and 100

20 Number Guessing Game between 1 and 100


Sr No. Topic (MySQL)

1 Create table of a Company and its Customers

2 Describe the Table

3 Insert values in the tables

4 To display table company and customer

5 To display table company which are having prize less than 30000
6 To display the name of the companies in reverse alphabetical
order
7 To add one more column total price with decimal] 10,2) to the
table customer
8 Select count(*), CITY from COMPANY group by CITY;

9 Select min(PRICE), max(PRICE) from CUSTOMER where QTY >


10;
10 Select PRODUCTNAME, CITY, PRICE from COMPANY,
CUSTOMER where COMPANY. CID=CUSTOMER.CID AND
PRODUCTNAME = ”MOBILE”
11 Create a table SCHOOL and its ADMIN

12 To display table company and customer

13 To display TEACHER_NAME, PERIODS of all teachers whose


periods are more than 25
14 To display all the information from the table SCHOOL in
descending order of experience
15 To display DESIGNATION without duplicate entries from the
table ADMIN
16 To display TEACHER_NAME, CODE and corresponding
DESIGNATION from tables SCHOOL and ADMIN of Male
teachers
17 To display all the information from the table SCHOOL in
ascending order of their time of working with the school (Date
of Joining)
18 To add joining of a new male teacher at the post of Principal
with these details (1333, ”Shantanu”,”Economics”,”2022-11-
17”,12,27)
19 To display the tables with principal joining
Program 1 - How to enter special
character in a normal string under print
command.?

x = ("this is \\\\ double backslash")

print(x)

y = ("these are /\\/\\/\\/\\/\\ mountains")

print(y)

z = ('He is\tawesome')

print(z)

w = ("\\\" \\n \\t \\\'")

print(w)

print (r"everything can be written ie. \\//\/\/ \n \t ...etc.")

Output:-

this is \\ double backslash

these are /\/\/\/\/\ mountains

He is awesome

\" \n \t \'

everything can be written ie. \\//\/\/ \n \t ...etc.


Program 2 - Write a program to enter two
integers and perform all arithmetic operations on them.
num1 = int(input("Enter first "))
num2 = int(input("Enter second number "))
print("Results:-")
print("Addition ",num1+num2)
print("Subtraction ",num1-num2)
print("Multiplication ",num1*num2)
print("Division ",num1/num2)
print("Modulus ", num1%num2)
print("Floor Division ",num1//num2)
print("Exponentiation ",num1 ** num2)

Output:-

Enter first 11

Enter second number 5

Results:-

Addition 16

Subtraction 6

Multiplication 55

Division 2.2

Modulus 1

Floor Division 2

Exponentiation 161051
Program 3 - Write a program to find
whether an input number is perfect or not?

n = int(input("Enter any number: "))

sum1 = 0

for x in range(1, n):

if n % x == 0:

sum1 = sum1 + x

if (sum1 == n):

print("The number is a Perfect number!")

else:
print("The number is not a Perfect number!")

Output:-

Enter any number: 1124567


The number is not a Perfect number!
Program 4 - Write a Program to find
factorial of the entered number.

num = int(input("Enter a number: "))

factorial = 1

if num < 0:

print(" Factorial does not exist for negative numbers")

elif num == 0:

print("The factorial of 0 is 1")

else:

for i in range(1,num + 1):

factorial = factorial*i
print("The factorial of",num,"is",factorial)

Output:-

Enter a number: 4
The factorial of 4 is 24

Program 5 - Write a program to calculate


the sum of series: 11 /1 + 22 /2 + 33 /3 + … + nn /n.
n=int(input("Enter a value of n "))

s=0

for i in range(1,n+1):

a=int((i**i)/i)

s=s+a
print ("The sum of the series is ", s)

Output:-
Enter a value of n 5
The sum of the series is 701

Program 6 - Write a program to calculate the


simple interest.
p = float(input("The principal amount is "))
t = float(input("The time period(in years) is "))
r = float(input("The rate of interest is "))
print(f"The Simple Interest is {(p*r*t)/100}")

Output:-
The principal amount is 13000

The time period(in years) is 4


The rate of interest is 7
The Simple Interest is 3640.0

Program 7 - Write a program for


calculating the area of a square, rectangle, circle.
print("What do you want to find area of:-\n")
x = input("Enter 'sq' for square, 'rect' for rectangle, 'cir' for circle ")
if x == "sq":
s = float(input("Enter side of the square "))
print(f"Area for Square is {s*s}")
elif x == "rect":
l = float(input("Enter length of the rectangle "))
b = float(input("Enter breath of the rectangle "))
print(f"Area for Rectangle is {l*b}")
elif x == "cir":
r = float(input("Enter radius of the circle "))
print(f"Area for circle is {(r*r*22)/7}")

Output:-
What do you want to find area of:-
Enter 'sq' for square, 'rect' for rectangle, 'cir' for circle sq
Enter side of the square 5
Area for Square is 25.0

What do you want to find area of:-


Enter 'sq' for square, 'rect' for rectangle, 'cir' for circle rect
Enter length of the rectangle 12
Enter breath of the rectangle 5
Area for Rectangle is 60.0

Program 9 - Write a program for


calculating the Total surface area, Lateral surface
area of a cylinder.
print("What do you want to find area of:-\n")
x = input("Enter 'tsa' for Total surface area, 'lsa' for Lateral surface area
")
if x == "tsa":
s = float(input("Enter radius of the cylinder "))
b = float(input("Enter height of the cylinder "))
print(f"Total surface area for Cube is {(2*22*s*(s+b))/7}")
elif x == "lsa":
l = float(input("Enter height of the cylinder "))
a = float(input("Enter radius of the cylinder "))
print(f"Lateral surface area for Cube is {(2*22*l*a)/7}")

Output:-
What do you want to find area of:-

Enter 'tsa' for Total surface area, 'lsa' for Lateral surface area tsa

Enter radius of the cylinder 7

Enter height of the cylinder 17

Total surface area for Cube is 1056.0

What do you want to find area of:-


Enter 'tsa' for Total surface area, 'lsa' for Lateral surface area lsa
Enter height of the cylinder 8
Enter radius of the cylinder 6
Lateral surface area for Cube is 301.714

Program 10 - Write a program for


calculating the Total surface area, Lateral surface
area of a cuboid.
print("What do you want to find area of:-\n")
x = input("Enter 'tsa' for Total surface area, 'lsa' for Lateral surface area
")
if x == "tsa":
c = float(input("Enter breath of the cuboid "))
b = float(input("Enter height of the cuboid "))
a = float(input("Enter length of the cuboid "))
print(f"Total surface area for cuboid is {2*(a*b + b*c + c*a)}", )
elif x == "lsa":
h = float(input("Enter height of the cuboid "))
l = float(input("Enter length of the cuboid "))
b = float(input("Enter breath of the cuboid "))
print(f"Lateral surface area for cubiod is {2*h*(l+b)}",)

Output:-
What do you want to find area of:-
Enter 'tsa' for Total surface area, 'lsa' for Lateral surface area tsa
Enter breath of the cuboid 6
Enter height of the cuboid 7
Enter length of the cuboid 9
Total surface area for cuboid is 318.0

Program 11 - Write a program for


calculating the Total surface area, Lateral surface
area of a cone.
print("What do you want to find area of:-\n")
x = input("Enter 'tsa' for Total surface area, 'lsa' for Lateral surface area
")
if x == "tsa":
c = float(input("Enter radius of the cone "))
b = float(input("Enter slant height of the cone "))
print(f"Total surface area for cone is {(22*c*(b+c))/7}")
elif x == "lsa":
h = float(input("Enter slant height of the cone "))
l = float(input("Enter radius of the cone "))
print(f"Lateral surface area for cone is {(h*22*l)/7}")

Output:-
What do you want to find area of:-
Enter 'tsa' for Total surface area, 'lsa' for Lateral surface area tsa
Enter radius of the cone 6
Enter slant height of the cone 9
Total surface area for cone is 282.857

Program 12 - Write a program for


calculating the volume of a cube, cuboid, cylinder,
cone, sphere.
print("What do you want to find Volume of:-")
x = input("Enter 'cube'-cube, 'cub'-cuboid, 'cyl'-cylinder, 'cone'-cone,'sp'-sphere ")
if x == "cube":
s = float(input("Enter side of the cube "))
print(f"Volume for cube is {s*s*s}")
elif x == "cub":
l = float(input("Enter length of the cubiod "))
b = float(input("Enter breath of the cubiod "))
h = float(input("Enter height of the cubiod "))
print(f"Volume for cubiod is {l*b*h}")
elif x == "cyl":
r = float(input("Enter radius of the cylinder "))
z = float(input("Enter height of the cylinder "))
print(f"Volume for cylinder is {(r*r*z*22)/7}")
elif x == "cone":
a = float(input("Enter radius of the cone "))
print(f"Volume for cone is {(r*r*h*22)/21}")
elif x == "cyl":
y = float(input("Enter radius of the cylinder "))
print(f"Volume for sphere is {(y*y*y*88)/21}")

Output:-
What do you want to find Volume of:-
Enter 'cube'-cube, 'cub'-cuboid, 'cyl'-cylinder, 'cone'-cone,'sp'-sphere cube
Enter side of the cube 6
Volume for cube is 216.0

Program 13 - Write a program for


calculating the Total surface area of a sphere.

print("let's find the area of shphere:-\n")


s = float(input("Enter radius of the sphere "))
print(f"Total surface area for sphere is {(4*22*s*s)/7}")
Output:-
let's find the area of shphere:-
Enter radius of the sphere 7
Total surface area for sphere is 616.0

Program 14 - Write a program for


calculating the Total surface area, Lateral surface
area of a hemisphere.
print("What do you want to find area of:-\n")
x = input("Enter 'tsa' for Total surface area, 'lsa' for Lateral area ")
if x == "tsa":
s = float(input("Enter radius of the hemisphere "))
print(f"Total surface area for hemisphere is {(3*22*s*s)/7}")
elif x == "lsa":
a = float(input("Enter radius of the hemisphere "))
print(f"Lateral surface area for hemisphere is {(2*22*a*a)/7}")

Output:-
What do you want to find area of:-
Enter 'tsa' for Total surface area, 'lsa' for Lateral surface area tsa
Enter radius of the hemisphere 14
Total surface area for hemisphere is 1848.0
Program 15 - Write a program to find
weather input number is prime or composite.
num = int(input("Enter a number: "))
if num > 1:
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
break
else:
print(num,"is a prime number")
else:
print(num,"is not a prime number")

Output:-
Enter a number: 345
345 is not a prime number

Program 16 - Write a program to


calculate the sum of squares of first n natural
numbers.
n = int(input("Enter value of n "))
s=0
for i in range(1, n+1):
s = s + (i*i)
print("Sum of squares = ", s)

Output:-
Enter value of n 6
Sum of squares = 91

Program 17 - Write a program to


calculate the sum of cubes of first n natural
numbers.
n = int(input("Enter value of n "))
s=0
for i in range(1, n+1):
s = s + (i*i*i)
print("Sum of cubes = ", s)

Output:-
Enter value of n 5
Sum of cubes = 225

Program 19 - Write a program to find


the biggest and smallest of given 4 numbers.

x = int(input("Enter first number "))


y = int(input("Enter second number "))
z = int(input("Enter third number "))
w = int(input("Enter fourth number "))
list1 = [x,y,z,w]
print("Largest number is ", max(list1))
print("Smallest number is ", min(list1))

Output:-
Enter first number 3458
Enter second number 7489
Enter third number 25
Enter fourth number 90743
Largest number is 90743
Smallest number is 25

Program 20 - Write a program to make


a Number Guessing Game between 1 and 100.
print("Guess the number between 1 and 100")
import random
n = random.randrange(1,100)
guess = int(input("Enter any number "))
while n!= guess:
if guess < n:
print("Too low")
guess = int(input("Enter number again "))
elif guess > n:
print("Too high!")
guess = int(input("Enter number again "))
else:
break
print("you guessed it right!!")

Output:-
Guess the number between 1 and 100
Enter any number 60
Too high!
Enter number again 15
Too high!
Enter number again 10
Too low
Enter number again 12
you guessed it right!!

Create a table COMPANY and its CUSTOMER:-


Describe the Table:-

Insert values in the tables:-

Query 1 - To display table company and customer.


Query 2 - To display table company which are having prize
less than 30000.

Query 3 - To display the name of the companies in reverse


alphabetical order.
Query 4 - To add one more column total price with decimal]
10,2) to the table customer.

Query 5 - Select count(*), CITY from COMPANY group by


CITY;
Query 6 - Select min(PRICE), max(PRICE) from CUSTOMER
where QTY > 10;

Query 7 – Select PRODUCTNAME, CITY, PRICE from


COMPANY, CUSTOMER where COMPANY.
CID=CUSTOMER.CID AND PRODUCTNAME =
”MOBILE”;

Create a table SCHOOL and its ADMIN:-


Describe the Table:-

Insert values in the tables:-


Query 8 - To display table company and customer.

Query 9 - To display TEACHER_NAME, PERIODS of all


teachers whose periods are more than 25.

Query 10 - To display all the information from the table


SCHOOL in descending order of experience.
Query 11 - To display DESIGNATION without duplicate
entries from the table ADMIN.

Query 12 - To display TEACHER_NAME, CODE and


corresponding DESIGNATION from tables SCHOOL and
ADMIN of Male teachers.

Query 13 - To display all the information from the table


SCHOOL in ascending order of their time of working with the
school (Date of Joining {DOJ}).
Query 14 - To add joining of a new male teacher at the post of
Principal with these details
(1333,”Shantanu”,”Economics”,”2022-11-17”,12,27).

Query 15 - To display the tables with principal joining.

You might also like