You are on page 1of 33

Reliance Foundation School, Koparkhairane

Session 2022 –23

Journal Questions
Class: XII
Subject: Computer Science (083)

I. Python Programs

1. Create user defined functions fact() to calculate factorial of a number and fibonacci()
to print Fibonacci series upto N terms using menu driven python code.

def fact():
from math import factorial
x = int(input('Enter number: '))
print('The factorial is:', factorial(x))

def fibonacci():
l = int(input('Enter sequence lenght: '))
fs = [0, 1]
for i in range(0, l):
if i != 0:
i = fs[i] + fs[i - 1]
fs.append(i)
print(fs)

fibonacci()
fact()

Output:
2. Write a menu driven python program with following functions:
a) reverse(): To reverse a string.
b) isPalindrome(): To check whether a string is palindrome or not.
c) search(): To find whether a substring is present in main string or not.
d) statistics(): To print number of upper case letter, lower case letters, digits,
alphabets and words in a string.
The program should run continuously till the time use doesn’t selects exit option.

def reverse(txt):
return txt[::-1]

def isPalindrome():
txt = input('Enter string to check if palindrome: ')
if txt.lower() == reverse(txt.lower()):
print('It is a palindrome')
else:
print('Not a palindrome')

def search(txt):
substring = input("Enter substring to search: ")
print('Number of occurrences:',txt.count(substring))
print('Substring first found at index:',txt.index(substring))

def statistics(txt):
ucase = 0
lcase = 0
digits = 0
words = len(txt.strip().split())
for i in txt:
if i.isupper():
ucase+=1
if i.islower():
lcase+=1
if i.isdigit():
digits+=1
print('Number of words:',words)
print('Number of uppercase letters',ucase)
print('Number of lowercase letters',lcase)
print('Number of alphabets:',ucase+lcase)
print('Number of digits:',digits)

while True:
print('''
1- reverse string
2 - check if palindrome
3 - search for substring
4 - statistics
5 - exit program
''')
userinput = int(input('Enter option number: '))
if userinput == 1:
txt = input("Enter string to reverse: ")
print('reversed:',reverse(txt))
elif userinput == 2:
isPalindrome()
elif userinput == 3:
txt = input("Enter mainstring: ")
search(txt)
elif userinput == 4:
txt = input("Enter string: ")
statistics(txt)
elif userinput == 5:
break
else:
print('Choose proper option number')

Output:
3. Write a menu driven python program with following functions:
a) add(): Which asks how many students data is to be entered and then allows user
to add data of that many number of students which includes students name, roll
number, marks in 3 subjects. The function should calculate average of every
student marks and then store it in list object.
b) remove(): Which asks for the name of student whose data is to be removed and
then removes that students entire data from the list object. Take necessary care to
remove the data even if user enters the students name in incorrect case. (Simran
should be removed even if user enters simran or SIMRAN etc.)
c) display(): Which displays all the students data.
The program should run continuously till the time use doesn’t selects exit option.

StudentData = []
def add():
n = int(input("Number of students data to be added: "))
for i in range(0,n):
from statistics import mean
name = input('Student name: ')
rollno = input('Student roll number: ')
english = float(input("Enter english marks: "))
maths = float(input("Enter maths marks: "))
science = float(input("Enter science marks: "))
StudentData.append([name, rollno, mean([english,maths,science])])

def remove():
name = input('Enter student name to remove: ')
for i in range(0,len(StudentData)):
if StudentData[i][0].lower() == name.lower():
del StudentData[i]
print(f'removed student {name} from data')

def display():
print("Name, Rollno, Average marks")
for i in StudentData:
print(i)
print()

while True:
print('''1- add student data
2- remove student data
3 - display student data
4 - exit''')
uinput = int(input('Enter option number: '))
if uinput == 1:
add()
elif uinput ==2:
remove()
elif uinput ==3:
display()
elif uinput ==4:
print('program exit')
break
else:
print('pls select proper option number')
print()
Output:
4. Write a python program to implement binary search.
#binary search
#needs a sorted array (ascending)

def binarysearch(arr,x,low,high):
if low>high:
print('element not found')
else:
mid = (low + high)//2
if x == arr[mid]:
print('at index:',mid)
elif x>arr[mid]:
binarysearch(arr,x,mid+1,high)
else:
binarysearch(arr,x,low,mid-1)

l = [1,2,3,4,5,7,8,10,15,21]
binarysearch(l,4,0,8)

Output:

For calling function - binarysearch(l,99,0,8)

5. Write a python program for different types of sorting:


a) Bubble sort
b) Insertion sort
c) Selection sort
#bubble sort
def bubblesort(arr):
for o in range(len(arr)):
for i in range(len(arr) - 1):
if arr[i] > arr[i + 1]:
arr[i], arr[i + 1] = arr[i + 1], arr[i]
print(arr)

def insertionsort(l):
a = len(l)
for i in range(1, a):
j = i - 1
while l[j] > l[i] and j >= 0:
l[i], l[j] = l[j], l[i]
i -= 1
j -= 1
print(l)

bubblesort([32,43,12,54,89,102,94])
insertionsort([2,5,1,4,10,55,0])
Output:

6. Create a text file “story.txt” in your folder using notepad with following content to do
the following: Total number of words, consonants, uppercase, lowercase, digits and
characters in the file.
def statistics(txt):
ucase = 0
lcase = 0
digits = 0
words = len(txt.strip().split())
for i in txt:
if i.isupper():
ucase+=1
if i.islower():
lcase+=1
if i.isdigit():
digits+=1
print('Number of words:',words)
print('Number of uppercase letters',ucase)
print('Number of lowercase letters',lcase)
print('Number of alphabets:',ucase+lcase)
print('Number of digits:',digits)

f = open('Story.txt','r')
txt = f.read()
statistics(txt)

Output:
Story.txt =
The bridge spanning a 100-foot gully stood in front of him as the last obstacle blocking him from
reaching his destination.
While people may have called it a "bridge", the reality was it was nothing more than splintered
wooden planks held together by rotting ropes.
It was questionable whether it would hold the weight of a child, let alone the weight of a grown
man.
The problem was there was no other way across the gully, and this played into his calculations of
whether or not it was worth the risk of trying to cross it.
7. Create a package as follows:

a) Module circle.py stores function AreaCircle() which calculates area of circle.


It should also store constant values such as pi = 3.14).
b) Module volume.py stores function VolumeCube() which calculates volume of cube.
help() function should give proper information about the module.
Make sure that above package meets the requirements of being a package. Also, you
should be able to import above package and/or its modules using import command.
Create a menu driven program to access the above created modules and functions.

For circle area


pi = 3.14
def circlearea(r):
A = pi*r**2
return A
For cube volume
def Cubevolume(a):
V = a**3
return V

from Geometry.Area import circle


print(circle.circlearea(3))
from Geometry.Volume import Cube
print(Cube.Cubevolume(3))
Output:

8. Write a program to show the detail of the student who scored the highest marks.
Data stored in “Data.csv” is given below :
Rollno, Name, Marks
1, Aman, 35
2, Kanak, 1
3, Anuj, 33
4, suman, 25
import csv
L = []
F = open('data.csv','r')
highest = 0
index = None
reader = csv.reader(F)
next(reader)
for i in reader:
L.append(i)
for j in range(len(L)):
if highest<int(L[j][2]):
highest = int(L[j][2])
index = j

print('Highest score:',highest)
print('details',L[index])
data.csv=
Rollno,Name,Marks
1,Aman,35
2,Kanak,1
3,Anuj,33
4,Suman,25

Output:
9. A binary file “emp.dat” has structure [employee id, employee name]. Write a function
delrec(employee number) in python that would read contents of the file “emp.dat”
and delete the details of those employee whose employee number is passed as
argument.
def delrec(employee_number):
L = []
import pickle
F = open("emp.dat",'rb')
data = pickle.load(F)
try:
for i in data():
if employee_number == i[0]:
continue
else:
L.append(i)
except EOFError:
pass
F.close()
print(L)
F = open("emp.dat",'wb')
pickle.dump(L,F)
F.close()

emp = input('Enter employee number')


delrec(emp)

10.Write a menu driven program for stack with the following options:
a) Push
b) Pop
c) Display
d) Exit

stack = []
while True:
print('''1- push element
2- pop element
3 - display stack
4 - exit''')
ui = int(input('Enter option number: '))
if ui ==1:
x = eval(input('Enter element to push: '))
stack.append(x)
elif ui ==2:
print('Element removed',stack.pop())
elif ui ==3:
print(stack)
elif ui ==4:
break
else:
print('Enter proper option number ')

Output:

II. Python Connectivity with Database Programs

11. Write a menu driven program for students’ records ( Rollno, Name, Marks, Grade) using
python connectivity to perform the following task:
a) To add record
b) To update record
c) To delete record
d) To display record
import mysql.connector as sql

def addrecord():
db = sql.connect(host='localhost',user = 'root', passwd = 'P@5sw0rd', database = 'school')
cursor = db.cursor()
rollno = int(input('Enter rollno of student: '))
name = input('Enter name of student: ')
marks = int(input('Enter student marks: '))
grade = input("Enter student grade: ")
cursor.execute(f"insert into studentdata(ROLLNO,NAME,MARKS,GRADE) values({rollno},'{name}',
{marks},'{grade}')")
db.commit()
cursor.close()
db.close()

def updaterecord():
column = input('Enter column to be updated: ')
value = input('Enter new value: ')
rollno = input("Enter rollno to be updated: ")
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='school')
cursor = db.cursor()
try:
cursor.execute(f"UPDATE studentdata set {column} = {value} where ROLLNO = {rollno}")
except:
cursor.execute(f"Update studentdata set {column} = '{value}' where ROLLNO = {rollno}")
db.commit()
cursor.close()
db.close()

def deleterecord():
rollno = int(input("Enter rollno of student to be deleted"))
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='school')
cursor = db.cursor()
cursor.execute(f"delete from Studentdata where ROLLNO = {rollno}")
db.commit()
cursor.close()
db.close()

def displayrecord():
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='school')
cursor = db.cursor()
cursor.execute("Select * from Studentdata")
data = cursor.fetchall()
for i in data:
print(i)

while True:
print('''1 - add record
2 - update record
3 - delete record
4 - display record
5 - exit''')
ui = int(input('Enter option number: '))
if ui ==1:
addrecord()
elif ui ==2:
updaterecord()
elif ui ==3:
deleterecord()
elif ui ==4:
displayrecord()
elif ui == 5:
break
else:
print('Enter proper option number')
Output:
12. Write a menu driven program for library records (LibID, Subject, Author_Name, Price)
using python connectivity to perform the following task:
a) To add record
b) To update record
c) To delete record
d) To display record

import mysql.connector as sql

def addrecord():
db = sql.connect(host='localhost',user = 'root', passwd = 'P@5sw0rd', database = 'school')
cursor = db.cursor()
libid = int(input('Enter Library Id of book: '))
book = input('Enter name of book: ')
subject = input('Enter book subject: ')
author = input('Enter book author: ')
price = int(input('Enter price of book: '))
cursor.execute(f"insert into libraryrecord (Libid,book,subject,author,price)
values({libid},'{book}','{subject}','{author}',{price})")
db.commit()
cursor.close()
db.close()

def updaterecord():
column = input('Enter column to be updated: ')
value = input('Enter new value: ')
libid = input("Enter Library ID to be updated: ")
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='school')
cursor = db.cursor()
try:
cursor.execute(f"UPDATE libraryrecord set {column} = {value} where Libid = {libid}")
except:
cursor.execute(f"Update libraryrecord set {column} = '{value}' where Libid = {libid}")
db.commit()
cursor.close()
db.close()

def deleterecord():
Libid = int(input("Enter Libray ID of book record to be deleted: "))
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='school')
cursor = db.cursor()
cursor.execute(f"delete from Libraryrecord where Libid = {Libid}")
db.commit()
cursor.close()
db.close()

def displayrecord():
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='school')
cursor = db.cursor()
cursor.execute("Select * from libraryrecord")
data = cursor.fetchall()
for i in data:
print(i)

while True:
print('''1 - add record
2 - update record
3 - delete record
4 - display record
5 - exit''')
ui = int(input('Enter option number: '))
if ui ==1:
addrecord()
elif ui ==2:
updaterecord()
elif ui ==3:
deleterecord()
elif ui ==4:
displayrecord()
elif ui == 5:
break
else:
print('Enter proper option number')

Output:
13. Write a menu driven program for employee records (Empid, First_Name, Last_Name,
Designation, Salary) using python connectivity to perform the following task:
a) To add record
b) To update record
c) To delete record
d) To display record
import mysql.connector as sql

def addrecord():
db = sql.connect(host='localhost',user = 'root', passwd = 'P@5sw0rd', database = 'Employee')
cursor = db.cursor()
Empid = int(input('Enter Employee number: '))
firstname = input('Enter first name: ')
lastname = input('Enter last name: ')
designation = input('Enter designation')
salary = int(input('Enter salary: '))
cursor.execute(f"Insert into emp_record (Empid,first_name,last_name,designation,salary)
values({Empid},'{firstname}','{lastname}','{designation}',{salary})")
db.commit()
cursor.close()
db.close()

def updaterecord():
column = input('Enter column to be updated: ')
value = input('Enter new value: ')
empid = int(input("Enter admission number to be updated: "))
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='employee')
cursor = db.cursor()
try:
cursor.execute(f"UPDATE emp_record set {column} = {value} where empid = {empid}")
except:
cursor.execute(f"Update emp_record set {column} = '{value}' where empid = {empid}")
db.commit()
cursor.close()
db.close()

def deleterecord():
empid = int(input("Enter employee id for record to be deleted: "))
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='employee')
cursor = db.cursor()
cursor.execute(f"delete from emp_record where empid = {empid}")
db.commit()
cursor.close()
db.close()

def displayrecord():
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='employee')
cursor = db.cursor()
cursor.execute("Select * from emp_record")
data = cursor.fetchall()
for i in data:
print(i)

while True:
print('''1 - add record
2 - update record
3 - delete record
4 - display record
5 - exit''')
ui = int(input('Enter option number: '))
if ui ==1:
addrecord()
elif ui ==2:
updaterecord()
elif ui ==3:
deleterecord()
elif ui ==4:
displayrecord()
elif ui == 5:
break
else:
print('Enter proper option number')
Output:

14. Write a menu driven program for hospital records (Admission_No, Patient_Name,
Doctor,Floor) using python connectivity to perform the following task:
a) To add record
b) To update record
c) To delete record
d) To display record
import mysql.connector as sql

def addrecord():
db = sql.connect(host='localhost',user = 'root', passwd = 'P@5sw0rd', database = 'hospital')
cursor = db.cursor()
admissionno = int(input('Enter admission number: '))
Patient = input('Enter patient name: ')
doctor = input('Enter doctor name: ')
floor = int(input('Enter floor: '))
cursor.execute(f"Insert into hospitalrecord (admissionno,patientname,doctor,floor)
values({admissionno},'{Patient}','{doctor}',{floor})")
db.commit()
cursor.close()
db.close()

def updaterecord():
column = input('Enter column to be updated: ')
value = input('Enter new value: ')
admissionno = int(input("Enter admission number to be updated: "))
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='hospital')
cursor = db.cursor()
try:
cursor.execute(f"UPDATE hospitalrecord set {column} = {value} where admissionno =
{admissionno}")
except:
cursor.execute(f"Update hospitalrecord set {column} = '{value}' where admissionno =
{admissionno}")
db.commit()
cursor.close()
db.close()

def deleterecord():
admissionno = int(input("Enter admission no of patient record to be deleted: "))
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='hospital')
cursor = db.cursor()
cursor.execute(f"delete from hospitalrecord where admissionno = {admissionno}")
db.commit()
cursor.close()
db.close()

def displayrecord():
db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='hospital')
cursor = db.cursor()
cursor.execute("Select * from hospitalrecord")
data = cursor.fetchall()
for i in data:
print(i)

while True:
print('''1 - add record
2 - update record
3 - delete record
4 - display record
5 - exit''')
ui = int(input('Enter option number: '))
if ui ==1:
addrecord()
elif ui ==2:
updaterecord()
elif ui ==3:
deleterecord()
elif ui ==4:
displayrecord()
elif ui == 5:
break
else:
print('Enter proper option number')
Output:
15. Create a menu driven application with details of employees like employee id, name and
salary.
Create a table employee with following columns in MySQL:

Perform the following operations:


a) Add a new employee with his/her id, name and salary.
b) View maximum and minimum salary of an employee.
c) Delete an employee based on his/her id provided by user. Provide error message if
employee doesn’t exist otherwise delete that employee from the table.
d) Show data of all the employees arranged in ascending order of salary.
import mysql.connector as sql
db = sql.connect(host='localhost',user='root',passwd='P@5sw0rd',database='employee')
def addrecord():
cursor = db.cursor()
name = input('Enter employee name: ')
eid = input('Enter employee ID: ')
salary = input("Enter employee salary: ")
cursor.execute(f"insert into emp(eid,ename,salary) values('{eid}','{name}',{salary})")
db.commit()
cursor.close()
def max_min():
cursor = db.cursor()
cursor.execute("select max(salary),min(salary) from emp")
data = cursor.fetchall()
print('max salary:',data[0][0])
print('min salary:',data[0][1])
cursor.close()

def delete_emp():
cursor = db.cursor()
empid = input('Enter empid: ')
try:
cursor.execute(f"delete from emp where eid ='{empid}'")
db.commit()
print('deleted employee record')
except:
print('invalid empid')

def displayrecord():
cursor = db.cursor()
cursor.execute("Select * from emp order by salary Asc")
data = cursor.fetchall()
for i in data:
print(i)
cursor.close()
while True:
print('''
1- Add records to emp table
2- Show maximum and minimum salary
3- delete an employee record
4- display emp records
5- exit''')
user_input = int(input('Enter choice number: '))
if user_input ==1:
addrecord()
elif user_input==2:
max_min()
elif user_input==3:
delete_emp()
elif user_input==4:
displayrecord()
elif user_input==5:
break
else:
print('Enter valid choice number...')
db.close()

Output:
16. Create a menu driven application which contains data about products like product id,
name, quantity, price.
Create a table product with following columns in MySQL:

Table product should have the following data already existing:

Perform the following operations:


a) Search all the products starting from the given alphabet entered by the user at run
time.
b) Search all the products whose price is less than or equal to the price entered by the
user at run time.
c) Update the product details in product table based on product id entered by user at
run time. Provide error message if product doesn’t exist otherwise update the
product details entered by the user.
d) Delete a product based on its id provided by user. If that product doesn’t exist, then
give an error message otherwise remove that product.

import mysql.connector as sql

db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='eshaan')

def searchbyalphabet():
cursor = db.cursor()
a = input('Enter starting alphabet: ')
cursor.execute(f"select * from productdata where name like '{a}%'")
data = cursor.fetchall()
for i in data:
print(i)
cursor.close()

def searchbyprice():
cursor = db.cursor()
p = input('Enter price to search up products: ')
cursor.execute(f"select* from productdata where price <= '{p}'")
data = cursor.fetchall()
for i in data:
print(i)
cursor.close()

def update():
cursor = db.cursor()
pid = input('Enter product id: ')
p = int(input('Enter new product price: '))
name = input('Enter name of new product: ')
try:
cursor.execute(f"Update productdata set price = {p},name = '{name}' where product_id =
'{pid}'")
print('updated...')
db.commit()
except:
print('invalid product id')
cursor.close()

def delete():
cursor = db.cursor()
pid = input('Enter product id: ')
try:
cursor.execute(f"delete from productdata where product_id = '{pid}'")
db.commit()
print('deleted record.')
except:
print('invalid product id')
cursor.close()

while True:
print('''
1- search by alphabet
2 -search by price
3- update product details
4-delete product data
5- exit''')
ui = int(input('Enter choice number: '))
if ui==1:
searchbyalphabet()
elif ui==2:
searchbyprice()
elif ui==3:
update()
elif ui==4:
delete()
elif ui==5:
break
else:
print('Enter proper choice number...')
db.close()

Output:
17. Create a menu driven application which contains data about customer like customer_ id,
name, gender and country.
Create a table customer with following columns in MySQL:

Table customer should have the following data already existing:

Perform the following operations:


a) Show total number of customers arranged country wise.
b) Search all the customers of a particular country where country name is entered by
user at run time. Give error message if no record is found.
c) Update the customer details in customer table based on customer id entered by user
at run time. Provide error message if customer id doesn’t exist otherwise update the
customer details entered by the user.
d) Add a new customer with his details as cid, cname, gender, country.

import mysql.connector as sql

db = sql.connect(host='localhost', user='root', passwd='P@5sw0rd', database='eshaan')

def displayrecord():
cursor = db.cursor()
cursor.execute("select * from customer order by country asc")
data = cursor.fetchall()
for i in data:
print(i)
cursor.close()

def searchbycountry():
cursor = db.cursor()
c = input('Enter country name: ')
cursor.execute(f"select * from customer where country like '{c}'")
data = cursor.fetchall()
cursor.close()
for i in data:
print(i)

def update():
cursor = db.cursor()
cid = input('Enter customer id: ')
cname = input('Enter customer name: ')
gender = input('Enter customer gender: ')
country = input('Enter country: ')
cursor.execute(f"update customer set cname='{cname}',gender ='{gender}',country='{country}'
where cid ='{cid}'")
db.commit()
cursor.close()

def addcustomer():
cursor = db.cursor()
cid = input('Enter customer id: ')
cname = input('Enter customer name: ')
gender = input('Enter customer gender: ')
country = input('Enter country: ')
cursor.execute(f"insert into customer(cid,cname,gender,country) values
('{cid}','{cname}','{gender}','{country}')")
db.commit()
cursor.close()

while True:
print('''
1- display customers by country
2- search ny country name
3- update customer details
4- Add customer
5 - exit''')
ui = int(input("Enter choice number: "))
if ui == 1:
displayrecord()
elif ui == 2:
searchbycountry()
elif ui == 3:
update()
elif ui == 4:
addcustomer()
elif ui == 5:
break
else:
print('Enter valid choice number')

db.close()

Output:
Mysql output after executing code:
18. Create a menu driven application for parking system to do the following:
Create a table parking with following columns in MySQL:

Perform the following operations:


a) Add a record with vehicle no, vehicle type, owner name taken from user at run time.
In date time should be the current system date and time which should be
automatically inserted.
b) Update a record on the basis of vehicle no entered by the user. If vehicle no doesn’t
exist then give error message otherwise update the record of that vehicle with
current system time as out date time.
c) Delete a record on the basis of vehicle no entered by the user. It vehicle no doesn’t
exist then given error message otherwise delete that vehicle details from parking
table.
d) Show all the records.

#menudriven program for parking lot system in mysql


# add record with vehicle no,vehicle type, owner name with automatic Indate time
import datetime
import mysql.connector as sql
db = sql.connect(host='localhost',user='root',passwd='P@5sw0rd',database='eshaan')
def addrecord():
current_time = datetime.datetime.now()
vnumber = input('Enter vehicle number: ')
vtype = input('Enter vehicle type: ')
ownername = input('Enter owner name: ')
cursor = db.cursor()
cursor.execute(f"insert into parking(vehicleno,vehicletype,ownername,in_date_time)
values('{vnumber}','{vtype}','{ownername}','{current_time}')")
db.commit()

def update():
cursor = db.cursor()
vnumber = input('Enter vehicle number: ')
datetimeout = datetime.datetime.now()
cursor.execute(f"update parking set out_date_time = '{datetimeout}' where vehicleno like
'{vnumber}'")
db.commit()
cursor.close()

def delete():
cursor = db.cursor()
vnumber = input('Enter vehicle number: ')
cursor.execute(f"delete from parking where vehicleno = '{vnumber}'")
db.commit()

def displayrecord():
cursor = db.cursor()
cursor.execute("Select * from parking")
data = cursor.fetchall()
for i in data:
print(i)
cursor.close()

while True:
print('''
1- Add records to parking
2- update record of vehicle
3- delete vehicle record
4- display table
5- exit''')
user_input = int(input('Enter choice number: '))
if user_input ==1:
addrecord()
elif user_input==2:
update()
elif user_input==3:
delete()
elif user_input==4:
displayrecord()
elif user_input==5:
break
else:
print('Enter valid choice number...')

db.close()

Output:
III. MySQL

19. Consider the following EMP and DEPT tables:


Write the SQL command to get the following:
a) Show the minimum, maximum and average salary of managers.
b) Count the number of clerks in the organization.
c) Display the designation-wise list of employees with name, salary and date of
joining.
d) Count the number of employees who are not getting commission.
e) Show the average salary for all departments with more than 5 working people.
f) List the count of employees grouped by DeptID.
g) Display the maximum salary of employees in each department.
h) Display the name of employees along with their designation and department
name.
i) Count the number of employees working in ACCOUNTS department.

20. Consider the following tables ACTIVITY and COACH. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (viii)

a) To display the name of all activities with their Acodes in descending order.
b) To display sum of PrizeMoney for each of the Number of participants groupings
(as shown in column ParticipantsNum 10,12,16)
c) To display the coach’s name and ACodes in ascending order of ACode from the
table COACH.
d) To display the content of the GAMES table whose ScheduleDate earlier than
01/01/2004 in ascending order of ParticipantNum.
e) SELECT COUNT(DISTINCT ParticipantsNum) FROM ACTIVITY;
f) SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM ACTIVITY;
g) SELECT SUM (PrizeMoney) FROM ACTIVITY;
h) SELECT DISTINCT ParticipantNum FROM COACH;

You might also like