0% found this document useful (0 votes)
24 views15 pages

Harshini CSC Record

The document contains a series of programming tasks and solutions in Python related to various topics such as computing factorials, Fibonacci series, checking palindromes, handling student marks, customer details, and database connectivity with MySQL. It includes examples of menu-driven programs, functions for conversions, and operations on data structures like dictionaries and lists. Additionally, it covers SQL commands for creating and manipulating a database, specifically for a school bus management system.

Uploaded by

harshini29042008
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)
24 views15 pages

Harshini CSC Record

The document contains a series of programming tasks and solutions in Python related to various topics such as computing factorials, Fibonacci series, checking palindromes, handling student marks, customer details, and database connectivity with MySQL. It includes examples of menu-driven programs, functions for conversions, and operations on data structures like dictionaries and lists. Additionally, it covers SQL commands for creating and manipulating a database, specifically for a school bus management system.

Uploaded by

harshini29042008
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/ 15

THE PSBB MILLENNIUM SCHOOL

GST AND GERUGAMBAKKAM


STD XII (AY 2025 – 26) - COMPUTER SCIENCE (083)
RECORD PROGRAMS
1.
QUESTION: Write a menu driven program to compute the following
AIM : To find Factorial of a given integer,fibbonacii series upto n numbers and check for a
palindrome
SOURCE CODE:
while True:
print("\nMenu:")
print("1. Factorial of a number")
print("2. Fibonacci series up to n terms")
print("3. Check Palindrome")
print("4. Exit")

choice = int(input("Enter your choice: "))

if choice == 1:
n = int(input("Enter a number: "))
fact = 1
for i in range(1, n+1):
fact *= i
print("Factorial:", fact)

elif choice == 2:
n = int(input("Enter number of terms: "))
a, b = 0, 1
print("Fibonacci series:", end=" ")
for i in range(n):
print(a, end=" ")
a, b = b, a+b
print()

elif choice == 3:
n = int(input("Enter a number: "))
temp = n
rev = 0
while n > 0:
digit = n % 10
rev = rev * 10 + digit
n //= 10
if temp == rev:
print("Palindrome")
else:
print("Not Palindrome")

elif choice == 4:
print("Exiting program...")
break

else:
print("Invalid choice, try again.")
OUTPUT:
2. Write a program to accept the marks for 5 subjects from the user for n students and do
the following,
a. Print the highest average scored
b. Print the number of students scored less than 40 in each subject
c. Compute the average marks of each student
d. Compute the percentage of each subject
n = int(input("Enter number of students: "))

marks = []

for i in range(n):
print("Enter marks of 5 subjects for Student", i+1)
student_marks = []
for j in range(5):
student_marks.append(int(input("Subject " + str(j+1) + ": ")))
marks.append(student_marks)

highest_avg = 0
for i in range(n):
avg = sum(marks[i]) / 5
if avg > highest_avg:
highest_avg = avg
print("Highest Average Scored:", highest_avg)

print("Number of students scoring less than 40 in each subject:")


for j in range(5):
count = 0
for i in range(n):
if marks[i][j] < 40:
count += 1
print("Subject", j+1, ":", count)

print("Average marks of each student:")


for i in range(n):
avg = sum(marks[i]) / 5
print("Student", i+1, ":", avg)

print("Percentage of each subject:")


for j in range(5):
total = 0
for i in range(n):
total += marks[i][j]
percentage = (total / (n * 100)) * 100
print("Subject", j+1, ":", percentage, "%")
3. Write a python program to input ‘n’ customers and their details like items bought, cost
and phone number etc. Store them in a dictionary and display all the details in a tabular
form.
n = int(input("Enter number of customers: "))

customers = {}

for i in range(n):
print("Enter details for Customer", i+1)
name = input("Name: ")
items = input("Items bought: ")
cost = float(input("Total cost: "))
phone = input("Phone number: ")
customers[name] = {"Items": items, "Cost": cost, "Phone": phone}

print("\n{:<15} {:<20} {:<10} {:<15}".format("Name", "Items Bought", "Cost", "Phone"))


print("-"*60)
for name, details in customers.items():
print("{:<15} {:<20} {:<10} {:<15}".format(name, details["Items"], details["Cost"],
details["Phone"]))
4. Write a program using function that takes amount – in – dollars and dollar – to – rupee
conversion price, it then returns the amount converted to rupees. Create a function in both
void and non-void forms.
def convert_to_rupees(amount, rate):
return amount * rate

def convert_and_print(amount, rate):


print("Amount in Rupees:", amount * rate)

amount = float(input("Enter amount in dollars: "))


rate = float(input("Enter conversion rate (1 dollar = ? rupees): "))

converted = convert_to_rupees(amount, rate)


print("Converted using non-void function:", converted)

convert_and_print(amount, rate)
5. Write a program using function to calculate volume of a box with appropriate default
values for its parameters. Your function should have the following input parameters,
a. Length of box
b. Width of box
c. Height of box
def volume(length=1, width=1, height=1):
return length * width * height

l = float(input("Enter length of box (press Enter for default 1): ") or 1)


w = float(input("Enter width of box (press Enter for default 1): ") or 1)
h = float(input("Enter height of box (press Enter for default 1): ") or 1)

print("Volume of the box:", volume(l, w, h))


6. Write a program with a definition of a method COUNTNOW(PLACES) to find and display
those places names in which there are more than 5 characters after storing the names of
places in a dictionary.
def COUNTNOW(PLACES):
print("Places with more than 5 characters:")
for key, value in PLACES.items():
if len(value) > 5:
print(key, ":", value)

n = int(input("Enter number of places: "))


PLACES = {}

for i in range(n):
code = input("Enter place code: ")
name = input("Enter place name: ")
PLACES[code] = name

COUNTNOW(PLACES)
7. Write an application based program (payroll, electricity bill, phone bill etc) to implement
LEGB rule and global keyword.

tax_rate = 0.1

def payroll():
base_salary = 50000
def calculate_bonus():
bonus = 5000
def total_salary():
total = base_salary + bonus
return total - (total * tax_rate)
return total_salary()
return calculate_bonus()

def update_tax(new_rate):
global tax_rate
tax_rate = new_rate

print("Payroll with default tax rate (10%):", payroll())

update_tax(0.2)
print("Payroll with updated tax rate (20%):", payroll())
8. Write a program to implement the guessing game as per the following criteria.
a. To guess an integer number
c. To guess a character from a list of character elements

import random

print("1. Guess an Integer Number")


print("2. Guess a Character from List")
choice = int(input("Enter your choice (1/2): "))

if choice == 1:
number = random.randint(1, 10)
guess = int(input("Guess a number between 1 and 10: "))
if guess == number:
print("Correct! You guessed it right.")
else:
print("Wrong! The number was", number)

elif choice == 2:
chars = ['a', 'b', 'c', 'd', 'e']
char = random.choice(chars)
guess = input("Guess a character from list {}: ".format(chars))
if guess == char:
print("Correct! You guessed it right.")
else:
print("Wrong! The character was", char)

else:
print("Invalid choice")

9. Read a text file line by line and display each word separated by a #.
10. Write a program to find the number of upper case, no of lower case, number of digits,
no of vowels, no of consonants, no of special characters and numbers of lines in a text file.

11. Write a program to remove all the lines that contains the character ‘A’ or ‘a’ in a file and
write it to another file.

12. Create a file named “test_report.txt”, write a function capitalize_sentence() to create a


copy of file “test_report.txt” name it as “file.txt”, which should convert the first letter of the
file and the first alphabetic character following a full stop into upper case.
13. Write a menu driven program to perform all the basic operations using dictionary on
student binary file such as inserting, updating, searching and deleting a record.
a. Insert records with the following data (data includes USN, Student_Name, Class, Sec,
Marks)
b. Ask for a student name and update their Marks
c. Search for a student record using USN
d. Delete records of students who have scored less than 13

14. Write a program to compute the Total salary of the employee and also calculate the size
of the binary file named “empfile.dat”. The file consists of the following fields : employee
number, employee name, basic salary, allowance. (HINT : Total salary = basic salary
+allowance)

15. Write a program to read User_Id and Password for a CSV file, count the number of
records and search for a particular record based on User_Id.

16. Create a CSV file “groceries” to store information of different items existing in a shop.
The information is to be stored w.r.t each item code, name, price, qty. Write a program to
accept the data from user and store it permanently in CSV file.
17. Coach Abhishek stores the races and participants in a dictionary. Write a
menu based python program, with separate user defined functions to perform
the following operations:
18. Write a Menu based program to add, delete and display the record of hostel using list as
stack Data Structure in Python. Record of Hostel Contains the following fields: Hostel
Number, Total Students and Total Rooms.
19. Write a Menu based program to push, pop and display the record of phone directory
using list as stack Data Structure in Python. Record of phone directory contains the following
fields: Pin code of the city and Name of the city.
SQL
CREATE DATABASE STD12;
USE STD12;

CREATE TABLE CLIENT (


C_ID INT PRIMARY KEY,
BrandName VARCHAR(50),
City VARCHAR(50),
P_ID VARCHAR(10)
);

CREATE TABLE PRODUCT (


P_ID VARCHAR(10) PRIMARY KEY,
ProductName VARCHAR(50),
Manufacturer VARCHAR(50),
Price INT
);

INSERT INTO CLIENT VALUES


(01, 'Maybelline', 'Delhi', 'FW05'),
(06, 'Loreal', 'Mumbai', 'BS01'),
(12, 'MAC', 'Delhi', 'SH06'),
(15, 'Sugar', 'Delhi', 'FW12'),
(16, 'Kay', 'Bangalore', 'TP01');

INSERT INTO PRODUCT VALUES


('TP01', 'Toner', 'LAK', 40),
('FW05', 'Face Wash', 'ABC', 45),
('BS01', 'Bronzer', 'ABC', 55),
('SH06', 'Shampoo', 'XYZ', 120),
('FW12', 'Face Wash', 'XYZ', 95);

SELECT * FROM PRODUCT;


SELECT * FROM CLIENT;

SELECT C.C_ID, C.BrandNam_


INTERFACE OF PYTHON WITH AN MYSQL DATABASE

21. Write a python database connectivity script that creates and inserts value into the table
SCHOOLBUS of database STD12.
import mysql.connector
con=mysql.connector.connect(host="localhost",user="root",passwd="root",database="STD1
2")
cur=con.cursor()
cur.execute("create table SCHOOLBUS(RtNo int,Area_Covered varchar(20),Capacity
int,NoOfStudents int,Distance int,Transporter varchar(30),Charges int)")
cur.execute("insert into SCHOOLBUS values(1,'A_001',100,120,10,'Shivam Travels',100000)")
cur.execute("insert into SCHOOLBUS values(2,'A_007',80,80,10,'Anand Travels',85000)")
cur.execute("insert into SCHOOLBUS values(3,'A_003',60,55,30,'Anand Travels',60000)")
cur.execute("insert into SCHOOLBUS values(4,'A_008',100,90,35,'Anand Travels',100000)")
cur.execute("insert into SCHOOLBUS values(5,'A_010',50,60,20,'Bhalla Co',55000)")
cur.execute("insert into SCHOOLBUS values(6,'A_004',70,80,30,'Yadhav Co',80000)")
cur.execute("insert into SCHOOLBUS values(7,'A_009',100,110,25,'Yadhav Co',100000)")
cur.execute("insert into SCHOOLBUS values(8,'A_005',40,40,20,'Speed Travels',55000)")
cur.execute("insert into SCHOOLBUS values(9,'A_002',120,120,10,'Speed Travels',100000)")
cur.execute("insert into SCHOOLBUS values(10,'A_006',100,100,20,'Kishen Tour',95000)")
con.commit()
con.close()
22. Write a python database connectivity script that display the records of table SCHOOLBUS
where distance is greater than 20.
import mysql.connector
con=mysql.connector.connect(host="localhost",user="root",passwd="root",database="STD1
2")
cur=con.cursor()
cur.execute("select * from SCHOOLBUS where Distance>20")
for row in cur:
print(row)
con.close()
23. Write a python database connectivity script to increase the charges by 100
import mysql.connector
con=mysql.connector.connect(host="localhost",user="root",passwd="root",database="STD1
2")
cur=con.cursor()
cur.execute("update SCHOOLBUS set Charges=Charges+100")
con.commit()
con.close()
24. Write a python database connectivity script that deletes records from the table
SCHOOLBUS if the transporter is ”Yadhav Co”.
import mysql.connector
con=mysql.connector.connect(host="localhost",user="root",passwd="root",database="STD1
2")
cur=con.cursor()
cur.execute("delete from SCHOOLBUS where Transporter='Yadhav Co'")
con.commit()
con.close()

You might also like