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

Computer Report File

ok
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)
3 views38 pages

Computer Report File

ok
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
You are on page 1/ 38

Morning Bells Academy

(High School)

Name: Suvra Shekhar Dey


Class: 12
Section: A
U. ID:
Subject: Computer Report File
CERTIFICATE
This is to certify that this report has been
made by “Suvra Shekhar Dey” of class XII
on the topic ‘Python and SQL’ under the
guidance of Mr. Saptarishi Podder during the
year 2023-2024 and have been completed
successfully.
ACKNOWLEDGEMENT
I would like to express my special thanks
of gratitude to my teacher “MR. Saptarishi
Podder SIR” as well as our principal
madam who gave me the golden
opportunity to do
this wonderful project which also helped
me in doing a lot of research and I came
to know about so many new things. I am
really thankful to them.
1. Write a Python function to check whether a number is ‘Perfect’ or
not.

CODE:

def is_perfect_number(num):
if num < 1:
return False
divisors_sum = 0
for i in range(1, num):
if num % i == 0:
divisors_sum += i
return divisors_sum == num
number_to_check = int(input("Enter a number to check : "))
if is_perfect_number(number_to_check):
print(number_to_check," is a perfect number.")
else:
print(number_to_check," is not a perfect number.")
OUTPUT
2. Write a Python program that reads each row of a given CSV 1le and
skip the header of the 1le. Also print the number of rows and the 1eld
names. CSV FILE:
department_id,department_name,manager_id,location_id
10,Administration,200,1700
20,Marketing,201,1800
30,Purchasing,114,1700
40,Human Resources,203,2400
50,Shipping,121,1500
CODE:
import csv
1elds = []
rows = []
with open('departments.csv', newline='') as csv1le:
data = csv.reader(csv1le, delimiter=' ', quotechar=',')
# Following command skips the 1rst row of the CSV 1le.
1elds = next(data)
for row in data:
print(', '.join(row))
print("\nTotal no. of rows: %d"%(data.line_num))
print('Field names are:')
print(', '.join(1eld for 1eld in 1elds))
OUTPUT:
3. Write a Python program to access a function inside a function

CODE:

def outer_function():
print("This is the outer function.")
def inner_function():
print("This is the inner function.")
# Call the inner function from the outer function
inner_function()
# Call the outer function
outer_function()
4. Write a Python program to detect the number of local variables.

CODE:

def count_local_variables():
# De1ne some local variables
var1 = 10
var2 = "Hello"
var3 = [1, 2, 3]
# Use locals() to get the local symbol table
local_variables = locals()

# Print the local variables


print("Local Variables:", local_variables)

# Print the number of local variables


num_local_variables = len(local_variables)
print("Number of Local Variables:", num_local_variables)
# Call the function
count_local_variables()
OUTPUT:
5. Write a Python program to create a 1le where all letters of English
alphabet are listed by speci1ed number of letters on each line.

CODE:
import string
def letters_1le_line(n):
with open("words1.txt", "w") as f:
alphabet = string.ascii_uppercase
letters = [alphabet[i:i + n] + "\n" for i in range(0, len(alphabet), n)]
f.writelines(letters)
letters_1le_line(3)

OUTPUT TEXT FILE:


6. Write a function RECCOUNT() to read the content of binary 1le
“NAMES.DAT” and display number of records ( each name
occupies 20 bytes in 1le ) in it.

NAMES.DAT:
SUVRA SHEKHAR DEY

COMPUTER SCIENCE
CODE:

def RECCOUNT(1le_path):
record_size = 20 # Size of each record in bytes
try:
with open(1le_path, 'rb') as 1le:
1le_content = 1le.read()
num_records = len(1le_content) // record_size
print(f"Number of records in {1le_path}: {num_records}")
except FileNotFoundError:
print(f"File {1le_path} not found.")
except Exception as e:
print(f"An error occurred: {e}")
1le_path = 'NAMES.DAT'
RECCOUNT(1le_path)
OUTPUT:
7. Write a function SCOUNT () to read the content of binary 1le
“NAMES.DAT” and display number of records (each name occupies
20 bytes in 1le) where name begins from “S” in it.

NAMES.DAT:
SUVRA SHEKHAR DEY
COMPUTER SCIENCE
CODE:
def SCOUNT():
try:
with open("NAMES.DAT", "rb") as 1le:
name_size = 20
s_names_count = sum(1 for _ in iter(lambda:
1le.read(name_size), b''))
print(f"Total Names beginning from 'S' are {s_names_count}")
except FileNotFoundError:
print("File not found.")
except Exception as e:
print(f"An error occurred: {e}")
SCOUNT()
OUTPUT:
8. Consider the following CSV 1le (emp.csv):
1, Peter,3500; 2, Scott,4000; 3, Harry,5000; 4, Michael,2500; 5,
Sam,4200
Write Python function DISPEMP () to read the content of 1le emp.csv
and display only those records where salary is 4000 or above.
CODE:
import csv
def DISPEMP():

try:
with open("emp.csv", "r") as 1le:
reader = csv.reader(1le)
header = next(reader)
print(','.join(header))
for row in reader:
if int(row[2]) >= 4000:
print(','.join(row))
except FileNotFoundError:
print("File not found.")
except Exception as e:print(f"An error occurred: {e}") DISPEMP()
OUTPUT:
9. Consider the following CSV 1le (emp.csv):
1,Peter,3500; 2,Scott,4000; 3,Harry,5000; 4,Michael,2500; 5,Sam,4200
Write a Python function SNAMES() to read the content of 1le
emp1.csv and display the employee record whose name begins from “S”.
Also show no. of employee with 1rst letter “S” out of total record.
Output should be: 2,Scott,4000 5,Sam,4200
Number of “S” names are 2,5
CODE:
import csv
def SNAMES():
try:
with open("emp1.csv", "r") as 1le:
reader = csv.reader(1le)
s_names_count = 0
header = next(reader)
print(','.join(header))
for row in reader:
if row[1].startswith('S'):
print(','.join(row))
s_names_count += 1
print(f"Number of 'S' names are {s_names_count}")
except FileNotFoundError:
print("File not found.")
except Exception as e:
print(f"An error occurred: {e}")
SNAMES()
OUTPUT:
DATABSE (SQL)

1.

i. To display details of all transactions of TYPE Withdraw from


TRANSACT table

Ans. select*from TRANSACT where TYPE= ‘Withdraw’;

ii. To display ANO and AMOUNT of all Deposit and Withdrawals


done in month of May 2017 from table TRANSACT.

Ans. select ANO, AMOUNT, TYPE from TRANSACT where DOT


like ‘2017-05%’;

iii. To display 1rst date of transaction (DOT) from table TRANSACT


for Account having ANO as 102

Ans. select DOT from TRANSACT where ANO=102


iv. To display ANO, ANAME, AMOUNT and DOT of those persons
from ACCOUNT and TRANSACT table who have done transaction
less than or equal to 3000

Ans. select ANO, ANAME from ACCOUNT, AMOUNT, DOT


from TRANSACT where AMOUNT <=3000;

v. SELECT ANO, ANAME FROM ACCOUNT WHERE


ADDRESS NOT IN ('CHENNAI', 'BANGALORE');

Ans.

ANO ANAME

103 Ali Reza

105 Simran Kaur

vi. SELECT DISTINCT ANO FROM TRANSACT;


DISTINCT ANO

101

103

102

Ans.

vii. SELECT ANO, COUNT(*), MIN(AMOUNT)


FROM TRANSACT GROUP BY ANO HAVING
COUNT(*)>1

Ans.
ANO COUNT(*) MIN(AMOUNT)

101 2 2500

103 2 1000

viii. SELECT COUNT(*), SUM(AMOUNT) FROM


TRANSACT WHERE DOT <= ‘2017-10-01’
Ans.

COUNT (*) SUM (AMOUNT)

2 5000

2.

(i) To display details of all employee in descending order of their DOJ


Ans. SELECT * FROM EMPLOYEE ORDER BY DOJ DESC;

(ii) To display NAME AND DESIG of those employees whose


sgrade is either „S02‟ or „S03‟
Ans. SELECT NAME,DESIG FROM EMPLOYEE WHERE
SGRADE IN ('S02','S03');

(iii) To display NAME, DESIG, SGRADE of those employee who


joined in the year 2009
Ans. SELECT NAME, DESIG, SGRADE FROM EMPLOYEE
WHERE DOJ LIKE '2009%';

(iv) To display all SGRADE, ANNUAL_SALARY from


SALGRADE [where ANNUAL_SALARY = SALARY*12]
Ans. SELECT SGRADE, SALARY*12 ANNUAL SALARY FROM
SALGRADE;

(v) To display number of employee working in each SALGRADE


from table EMPLOYEE
Ans. SELECT SGRADE, COUNT(*) FROM EMPLOYEE GROUP
BY SGRADE;

(vi) To display NAME, DESIG, SALARY, HRA from tables


EMPLOYEE and SALGRADE where SALARY is less than 50000
Ans. SELECT NAME,DESIG,SALARY,HRA FROM EMPLOYEE
E,SALGRADE S WHERE E.SGRADE=S.SGRADE AND
SALARY<=50000;

(vii) Select MIN(DOJ), MAX(DOB) from employee;


Ans.
MIN(DOJ) MAX(DOB)

(viii) Select SGrade, Salary+HRA from SalGrade where SGrade=


“S02”;
Ans.

SGRADE SALARY+HRA

S02 44000

(i) Select count(distinct SGrade) from employee;


Ans.
COUNT(*)

(ii) Select sum(salary), avg(salary) from salgrade;


Ans

SUM(SALARY) AVG(SALARY)

112000 37333.33
3.

(i) To display details of all Trains which starts from New Delhi
Ans. SELECT * FROM TRAINS WHERE START='NEW
DELHI'
(ii) To display PNR, PNAME, GENDER and AGE of all
passengers whose AGE is below 50
Ans. SELECT PNR,PNAME,GENDER,AGE FROM PASSENGER
WHERE AGE<50
(iii) To display total numbers of MALE and FEMALE passengers
Ans. SELECT GENDER,COUNT(*) FROM PASSENGERS
GROUP BY GENDER
(iv) To display records of all passengers travelling in trains whose
TNO is 12015
Ans. SELECT * FROM PASSENGERS WHERE TNO=12015
(v) SELECT MAX(TRAVELDATE),MIN(TRAVELDATE)
FROM PASSENGERS WHERE GENDER=‟FEMALE‟;
Ans.
MAX (TRAVELDATE) MIN (TRAVELDATE)

2018-11-10 2018-05-09

(vi) SELECT END, COUNT(*) FROM TRAINS GROUP BY END


HAVING COUNT(*)>1;
Ans.
END COUNT (*)

HABIBGANJ 2

AMRITSAR JN. 2

NEW DELHI 4
(vii) SELECT DISTINCT TRAVELDATE FROM PASSENGERS;
Ans.

You might also like