KR MANGALAM WORLD SCHOOL
COMPUTER SCIENCE (083)
PRACTICAL FILE
SESSION: 2025-26
Student Name: Saatvik Khandelwal
Roll Number:
Class: 12-A
Submitted to: Ms. Shelly Arora
1
INDEX
S NO. PROGRAMS PAGE
NO.
1. WAP TO PRINT THE SUM OF THE SERIES 1+X/1!+X2/2!+....XN/(N)! - 4
EXPONENTIAL SERIES .
2. WAP TO ACCEPT A NUMBER, FIND AND DISPLAY WHETHER IT'S A 5
ARMSTRONG NUMBER OR NOT .
3. WAP TO PRINT THE FIBONACCI SERIES USING FUNCTION . 6
4. WAP TO DISPLAY SECOND LARGEST ELEMENT OF A GIVEN LIST . 7
5. WAP IN PYTHON TO INPUT NAMES OF 'N' COUNTRIES AND THEIR 8
CAPITAL AND CURRENCY, STORE IT IN A DICTIONARY AND DISPLAY
IN TABULAR FORM. ALSO SEARCH AND DISPLAY FOR A PARTICULAR
COUNTRY .
6. WRITE A FUNCTION CALLED CALCULATE_AREA() THAT TAKES BASE 9
AND HEIGHT AS INPUT ARGUMENTS AND RETURNS AREA OF A
TRIANGLE AS AN OUTPUT .
7. WRITE A PYTHON FUNCTION TO MULTIPLY ALL THE NUMBERS IN A 10
LIST .
8. WRITE A PYTHON FUNCTION TO CALCULATE THE FACTORIAL OF A 11
NUMBER (A NON-NEGATIVE INTEGER). THE FUNCTION ACCEPTS THE
NUMBER WHOSE FACTORIAL IS TO BE CALCULATED AS THE
ARGUMENT .
9. WRITE A PYTHON FUNCTION THAT TAKES A NUMBER AS A 12
PARAMETER AND CHECKS WHETHER THE NUMBER IS PRIME OR
NOT .
2
10. WRITE A PYTHON FUNCTION THAT CHECKS WHETHER A PASSED 13
STRING IS A PALINDROME OR NOT .
11. WRITE A METHOD EVENSUM (NUMBERS) TO ADD THOSE VALUES IN 14
THE TUPLE OF NUMBERS WHICH ARE EVEN .
12. SQL QUESTION-1 15
13. SQL QUESTION-2 18
14. SQL QUESTION-3 20
15. SQL QUESTION-4 23
3
Program-1: WAP to print the sum of the series 1+x/1!+x2/2!
+....xn/(n)! - exponential series.
Code:
x = float(input("Enter x: "))
n = int(input("Enter n: "))
sum = 0
for i in range(n + 1):
power = 1
for j in range(i):
power *= x
fact = 1
for j in range(1, i + 1):
fact *= j
sum += power / fact
print("Sum of the series:", sum)
Output:
4
Program-2: WAP to accept a number, find and display whether
it's a Armstrong number or not.
Code:
n=int(input("Enter a number: "))
n_str=str(n)
sum_of_powers=0
n_digits=len(n_str)
for digit in n_str:
sum_of_powers += int(digit) ** n_digits
if sum_of_powers == n:
print("It is an Armstrong number")
else:
print("It is not an Armstrong number")
Output:
5
Program-3: WAP to print the Fibonacci series using function.
Code:
def fibonacci(n):
a, b = 0, 1
for _ in range(n):
print(a, end=' ')
a, b = b, a + b
terms=int(input("Enter the number of terms: "))
print("Fibonacci Series: ")
fibonacci(terms)
Output:
6
Program-4: WAP to display second largest element of a given
list.
Code:
A=[1,12,53,64,22,65]
print("List: ",A)
D=sorted(A)
B=max(D)
C=len(D)
for i in range(C):
if D[i]==B:
print("The second largest number is: ", D[i-1])
Output:
7
Program-5: WAP in python to input names of 'n' countries and
their capital and currency, store it in a dictionary and display in
tabular form. Also search and display for a particular country.
Code:
CNT = dict()
i=1
flag = 0
n = int(input("Enter number of entries: "))
while i <= n:
Cnt = (input("\nEnter the name of the country: "))
Cpt = input("Enter the capital of the country: ")
Crcy = input("Enter the currency used: ")
b = (Cnt, Cpt, Crcy)
CNT[Cnt] = b
i=i+1
l = CNT.keys()
for i in l:
print("\nCountry name: ", i,)
z = CNT[i]
print("Capital\t", "Currency\t",)
for j in z:
print(j, end="\t")
Output:
8
Program-6: Write a function called calculate_area() that takes
base and height as input arguments and returns area of a
triangle as an output.
Code:
def calculate_area(b,h):
Triangle_area=(b*h)*0.5
print("Area of triangle= ",Triangle_area)
calculate_area(2,2)
Output:
9
Program-7: Write a Python function to multiply all the numbers
in a list.
Code:
def LM(n):
L=[]
for i in range(n):
a=int(input("Enter the number into list: "))
L.append(a)
print("List: ",L)
X=1
for k in L:
X=X*k
print("Product of all numbers: ",X)
LM(5)
Output:
10
Program-8: Write a Python function to calculate the factorial of
a number (a non-negative integer). The function accepts the
number whose factorial is to be calculated as the argument.
Code:
def factorial(n):
result = 1
for i in range(2, n + 1):
result *= i
return result
a=int(input("Enter the number whose factorial is to be calculated: "))
Fac=factorial(a)
print("Factorial of ", a ,"= ", Fac)
Output:
11
Program-9: Write a Python function that takes a number as a
parameter and checks whether the number is prime or not.
Code:
def is_prime(num):
if num <= 1:
return False
for i in range(2, num):
if num % i == 0:
return False
return True
n = int(input("Enter a number: "))
if is_prime(n):
print(n, "is a prime number.")
else:
print(n, "is not a prime number.")
Output:
12
Program-10: Write a Python function that checks whether a
passed string is a palindrome or not.
Code:
def is_palindrome(String):
if String==String[::-1]:
return ("The word is a palindrome")
else:
return("The word is not a palindrome")
A=input("Enter the word: ")
B=is_palindrome(A)
print(B)
Output:
13
Program-11: Write a method EvenSum (NUMBERS) to add those
values in the tuple of NUMBERS which are even.
Code:
def EvenSum(NUMBERS):
total = 0
for num in NUMBERS:
if num % 2 == 0:
total += num
print("Sum of even numbers:", total)
EvenSum((1,2,3,4,5,6))
Output:
14
SQL QUERIES
Q1
a. Display all information from movie.
Query-
SELECT* FROM MOVIES;
15
b. Display the type of movies.
Query-
SELECT Type FROM MOVIES;
c. Display movieid, moviename, total_earning by showing
the business done by the movies.Calculate the business
done by movie using the sum of productioncost and
businesscost.
Query-
SELECT Movie_ID, MovieName, (ProductionCost+BusinessCost)
AS Total_Earnings FROM MOVIES
16
d. Display movieid, moviename and productioncost for all
movieswith productioncost greater than 150000 and less
than1000000.
Query-
SELECT Movie_ID, MovieName, ProductionCost FROM
MOVIES WHERE ProductionCost>150000 AND
ProductionCost<1000000;
e. Display the movie of type action and romance.
Query-
SELECT MovieName FROM MOVIES WHERE Type IN
('Action','Romance');
f. Display the list of movies which are going to release in
February 2022.
Query-
SELECT* FROM MOVIES WHERE ReleaseDate LIKE
'2022-02-%';
17
Q2.
I. Create a database “Sports”.
Query-
CREATE DATABASE SPORTS;
18
II. Create a table “TEAM” with following considerations:
a. It should have a column TeamID for storing an integer value
between 1 to9, which refers to unique identification of a team.
b. Each TeamID should have its associated name (Team Name),
which should be a string of length not less than 10characters.
c. Using table level constraint, make TeamID as the primary key.
Query-
CREATE TABLE TEAM (TeamID INT PRIMARY KEY, TeamName
VARCHAR(50) NOT NULL);
III. Show the structure of the table TEAM using a SQL statement.
Query-
DESC TEAM;
IV. As per the preferences of the students four teams were formed as given
below. Insert these four rows in TEAM table:
a. Row 1: (1,Tehlka)
b. Row 2: (2,Toofan)
c. Row 3: (3,Aandhi)
d. Row 3: (4,Shailab)
Query-
INSERT INTO TEAM (TeamID, TeamName) VALUES
(1, 'Tehlka'),
(2, 'Toofan'),
(3, 'Aandhi'),
19
(4, 'Shailab');
V. Show the contents of the table TEAM using a DML statement.
Query-
SELECT* FROM TEAM;
VI. Now create another table MATCH_DETAILS and insert data as shown
below. Choose appropriate data types and constraints for each attribute.
Q3 Write following queries based on above table:
a. Display the matchid, teamid, teamscore who scored more than 70 in first
ining along with team name.
Query-
20
SELECT M.MatchID,M.FirstTeamID,M.FirstTeamScore, T.TeamName from
MatchTable M, TEAM T WHERE M.FirstTeamID=T.TeamID AND
FirstTeamScore>70;
b. Display matchid, teamname and secondteamscore between 100 to160.
Query-
SELECT M.MatchID,M.SecondTeamScore, T.TeamName from
MatchTable M, TEAM T WHERE M.SecondTeamID=T.TeamID AND
SecondTeamScore BETWEEN 100 AND 160;
c. Display matchid, team names along with matchdates.
Query-
SELECT MatchID, T1.TeamName, T2.TeamName, MatchDate
21
FROM MatchTable, TEAM T1, TEAM T2
WHERE MatchTable.FirstTeamID = T1.TeamID
AND MatchTable.SecondTeamID = T2.TeamID;
d. Display unique team names
Query-
SELECT DISTINCT TeamName FROM TEAM;
e. Display matchid and matchdate played by Anadhi and Shailab.
Query-
SELECT MatchID, MatchDate
FROM MatchTable, TEAM T1, TEAM T2
WHERE MatchTable.FirstTeamID = T1.TeamID
22
AND MatchTable.SecondTeamID = T2.TeamID
AND (T1.TeamName = 'Aandhi' AND T2.TeamName = 'Shailab');
Q4. Consider the following table “Stock” and write the queries:
23
a. Display all the items in the ascending order of stockdate.
Query-
SELECT* FROM Stock ORDER BY stockdate;
b. Display maximum price of items for each dealer individually as per dcode
from stock.
Query-
SELECT dcode,MAX(unitprice) as "Max Price" FROM Stock GROUP
BY dcode;
c. Display all the items in descending orders of item names.
Query-
SELECT* FROM Stock ORDER BY item DESC;
24
d. Display average price of items for each dealer individually as per dcode from
stock which average price is more than5.
Query-
SELECT dcode,AVG(unitprice) as "AVG Price" FROM Stock GROUP
BY dcode HAVING AVG(unitprice)>5;
e. Display the sum of quantity for each dcode.
Query-
SELECT dcode,SUM(qty) as "SUM OF QUANTITY" FROM Stock
GROUP BY dcode;
25