Practical File Ques Class XII 2024-25
Practical File Ques Class XII 2024-25
((45,45,40),(35,40,38),(36,30,38),(25,27,20),(10,15,20))
Also add a function that computes total marks and average marks obtained by each student.
Q 12. Write a Python function SORT to sort (ascending and descending) a dictionary by value.
Sample Output
dictionary = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
Ascending order = [ (0, 0), (2, 1), (1, 2), (4, 3), (3, 4) ]
Descending order = {3: 4, 4: 3, 1: 2, 2: 1, 0: 0}
Q 13. Write a function AMCount() in Python, which should read each character of a text file
STORY.TXT,
should count and display the occurance of alphabets 'A' and 'M' (including small cases 'a' and
'm 'too).
Q 15. Write a program to take two numbers as input and display any random number between those
two numbers.
import random
print(random_between(num1, num2))
Q 16. Write a program to take a number and display its square root using function of math module.
import math
def square_root(num):
return math.sqrt(num)
number = float(input("Enter a number: "))
print(square_root(number))
Q 17. Write a program to take a floating point number with 5 decimal digits as input and display
after rounding of that value to 2 decimal places using function of math module
import math
n=float(input("Enter number with 5 decimal digits:"))
r=round(n,2)
print("Output:",r)
Q 18. Write a program to create a Stack for storing only odd numbers out of all the numbers entered
by the user.
Display the content of the Stack along with the largest odd number in the Stack. (Hint. Keep popping
out the elements from stack and maintain the largest element retrieved so far in a variable. Repeat
till Stack is empty).
put("Enter no of elements:"))
for i in r l=[]
n=int(in ange(0,n):
k=int(input("Enter element of list:"))
if k%2!=0:
l.append(k)
print(l)
max=l[0]
for i in range(1,len(l)):
if max<l[i]:
max=l[i]
print("Largest number:",max)
Q 20. Write a code to establish connectivity between python and MySQL to create a new database
‘SALES’ and a new table ‘SALESPERSON’.
import mysql.connector
def create_database():
conn = mysql.connector.connect(host='localhost', user='username', password='password')
cursor = conn.cursor()
cursor.execute("CREATE DATABASE")
cursor.close()
conn.close()
create_database()
print("Database created successfully.")
Q 21. Write a code to establish connectivity between python and MySQL to insert data into the
table ‘SALESPERSON’. Also display the data of the table.
import mysql.connector
conn = mysql.connector.connect( host="localhost", user="username", password="password",
database="database")
cursor = conn.cursor()
cursor.execute("INSERT INTO SALESPERSON (name, sales_amount) VALUES ('BOB', 500)""")
cursor.execute("SELECT * FROM SALESPERSON")
rows = cursor.fetchall()
for row in rows:
on print(row)
cursor.close()
cn.close()
Q 22. Create a table employee insert records in it and perform the following operations:
i. Write a query to display details of all employees
ii. Write a query to display average salary of employees of department accounts
iii. Write a query to display sum of salary of all employees
iv. Write a query to add a column office_site with varchar and size 60 in employee table
v. Write query to display all details of employees whose first name starts with D
vi. Display details of all employees in order of their salary
vii. Display average salary of employee under manager ‘Wardman’
viii. Write a query to delete a column manager from table employee
ix. Update salary of employee E345 to 35,000
x. Delete data of ‘Mohan’ from table employee
xi. Write a query to count employees department Wise
xii. Write a query to show employee details do not have any manager
i. select * from employees;
ii.