0% found this document useful (0 votes)
26 views37 pages

Annual Practical File 2

Uploaded by

ksaksham140
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)
26 views37 pages

Annual Practical File 2

Uploaded by

ksaksham140
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/ 37

Class XII

CBSE
Board Examination
Practical File
Submitted by :
AYUSH CHHETRI - XIIA
INDEX
PYTHON PROGRAMS
S. Practical’s Name Page Teacher’s
No. No. Sign
1 Write a Program in Python that generates 4 terms of an AP by
providing Initial and Step values to a function that returns first
four terms of the series.
2 Write a Python Function that receives an octal number and
prints the equivalent number in other number bases that is in
decimal, binary and hexadecimal equivalents.
3 Write a Python Function to check whether a string is a
Pangram or not.

4 Write a Python Function that takes amount-in-Dollar and


Dollar-to-Rupee conversion price; it then returns the amount
converted to Rupees.
5 Write a Python Function namely nthRoot() that receives two
parameters x and n and return nth root of x.

6 Write a Function AMCount() in Python, which should read


each character of a text file “STORY.TXT” ,should count and
display the occurrences of alphabets A and M including small
cases a and m too.
7 Write a Function Count() in Python to read contents from file
“COMPUTERSCIENCE.TXT”, to count the occurrence of the
words “computer” or “python”.
8 Write a Function DISPLAYWORDS() in Python to read lines
from a text file “Story.txt” and display those words which are
less than 4 characters.
9 Write a Program in Python to add details of
employees(Employee_ID,Department,Salary) in a Binary file
and display them.
10 Write a Program in Python to add 2 lines in a Binary file and
Display them.
11 Write a Program in Python to modify the data of a specific
Employee in a Binary file containing Employees Records

12 Write a Program to insert Records of 5 Students(Roll no,


Name, Marks) in a CSV file.

13 Write a program to insert Emp_ID, Name and salary of 5


Employees in a CSV file “emp.csv”.

14 Write a Program in Python which adds any random five odd


numbers in a list that fall between the highest and the
lowest number
15 Write a program in python to implement stack operations
like push, pop, peek using list.

SQL QUERIES
1 Consider table “emp” with columns emp_id, emp_name,
emp_dept, salary, joining_date.
--Implement the following SQL commands on the table emp--
 List all employees with their department names.
 Find department wise total salary.
 Increase the salary of the employees by 10%.
 Insert a new record of an employee.
 Count the number of employee in each
department.
2 Consider the table “electronic_devices” with columns
dev_id, dev_name, dev_type, dev_brand, price.
--Implement the following SQL commands on the table
electronic_devices—
 Display all the items whose price is greater than
50000.
 Display the names of all devices along with their
brand in alphabetical order.
 Increase the price of all the devices by 5%.
 Count the number of devices made by each brand
 Discount the price of all the devices by 10%
3 Consider the table “result” with columns student_id,
student_name, student_marks, student_class,
student_section.
--Implement the following SQL commands on the table result—
 Display the names of all the students who scored
above 90 marks.
 Display the name of students in alphabetical order.
 Display the number of students in each section.
 Display the name of the student with highest and
lowest marks.
 Find the average marks of all students.
4 Consider the table “payment” with columns customer_id,
customer_name, amount, mode, payment date and
“paymentdue” with columns customer_id,
customer_name, payment_due, due_date
--Implement the following SQL commands on the table payment
and paymentdue—
 Display the sum of total amount paid by different mods.
 Display the name of customer who’s due amount
exceeds 10000
 Create a report that summarize payment received and
payment due .
 Display the count of all customers and the amount they
paid in descending order.
 Display the name of the customer with highest amount
and the lowest amount due.

5 Consider the table “club” with columns coach_id,


coach_name, age, sports,date_of_app, salary,sex
--Implement the following SQL commands on the table
club—
 Display the list of the coach who is playing karate.
 Display the name of the coach whose name starts
with S.
 Display the total salary paid to coach gender wise.
 Select minimum age from the club where sex is “M”.
 Select average age from club group by sex.
Python-SQL Connectivity
1 Write a program to connect MySQL database and create a
table with employee records.
2 Write a program to insert data on the employee with user
input.
3 Write a program to display the names of employee whose
salary is greater than 80000.
4 Write a program to increase the salary of the employees by
5%
Practical-1

Question: Write a Program in Python that generates 4 terms of an AP by providing Initial and
Step values to a function that returns first four terms of the series .

Input:
def Series(a,b):

returna,a+b,a+b*@,a+b*3

a = int(input(“Enter the initial value of the AP series:”))

b = int(input(“Enter the step value of the AP series:”))

print(“Series with initial value”,a,”and step value”,b,”goes as”)

t1,t2,t3,t4=Series(a,b)

print(t1,t2,t3,t4)

Output:
Practical-2

Question: Write a Python Function that receives an octal number and prints the equivalent
number in other number bases that is in decimal, binary and hexadecimal equivalents.

Input:

def oct2other(n):

print(“Passed octal number”,n)

numstr = str(n)

decNum = int(numstr,8)

print(“Number in Decimal:”,decNum)

print(“Number in Binary:”,bin(decNum))

print(“Number in HexaDecimal:”,hex(decNum))

num = int(input(“Enter an octal number:”))

oct2other(num)

Output:
Practical-3

Question: Write a Python Function to check whether a string is a Pangram or not.

Input:

string = input("Enter the string")

string=string.replace("","")

string= string.lower()

alphabets = "abcdefghijklmnopqrstuvwxyz"

c= 0

for i in alphabets:

if i in string:

c+=1

if c==len(alphabets):

print("The string is a pangram")

else:

print("the string is not a pangram:")

Output:
Practical-4

Question: Write a Python Function that takes amount-in-Dollar and Dollar-to-Rupee


conversion price; it then returns the amount converted to Rupees

Input:

def Dollar2Rupee(s):

return s*84

amount_in_rupee = int(input("Enter the amount in Rupees :"))

amount_in_Dollars = Dollar2Rupee(amount_in_rupee)

print(amount_in_rupee,"Rupees are equal to $",amount_in_Dollars,"Dollars")

Output:
Practical-5

Question: Write a Python Function namely nthRoot() that receives two parameters x and n
and return nth root of x.

Input:

def nthRoot(x,n):

return x**(1/n)

x = int(input("Enter the value of x:"))

n = int(input("Enter the value of n:"))

result = nthRoot(x,n)

print("The",n,"th Root of ",x,"IS",result)

Output:
Practical-6

Question: Write a Function AMCount() in Python, which should read each character of a text
file “STORY.TXT” ,should count and display the occurrences of alphabets A and M including
small cases a and m too.

Input:

def AMCount():

f = open("STORY.txt","r")

A,M=0,0

r = f.read()

for i in r:

if i[0]=="A" or i[0]=="a":

A+=1

elif i[0]=="M" or i[0]=="m":

M+=1

print("Occurrences of A or a :",A,"and occurrence of M or m :",M)

AMCount()

Output :
Practical-7

Question: Write a Function Count() in Python to read contents from file


“COMPUTERSCIENCE.TXT”, to count the occurrence of the words “computer” or “python”.

Input:

def count():

f = open("COMPUTERSCIENCE.txt","r")

d = f.readlines()

c=0

s=0

for i in d:

if "computer" in i:

c+=1

if "python" in i:

s+=1

print(" The word computer occurred ",c,"times and python


occured",s,"times")

count()

Output:
Practical-8

Question: Write a Function DISPLAYWORDS() in Python to read lines from a text file
“Story.txt” and display those words which are less than 4 characters.

Input:

def DISPLAYWORDS():

f = open("story.txt","r")

r = f.read()

r = r.split()

for i in r:

if len(i)>4:

print(i)

f.close()

DISPLAYWORDS()

Output:
Practical-9

Question: Write a Program in Python to add details of


employees(Employee_ID,Department,Salary) in a Binary file and display them.

Input:
import pickle

l = []

for i in range(5):

x = int(input("Enter the Employee_ID :"))

y = input("Enter the Department of the Employee :")

z = int(input("Enter the salary of the Employee :"))

p = str(x)+y+str(z)+"\n"

l.append(p)

file1 = open("emp.dat","ab")

pickle.dump(l,file1)

file1 = open("emp.dat","rb")

x=pickle.load(file1)

for i in x:

print(i)

Output:
Practical-10

Question: Write a Program in Python to add 2 lines in a Binary file and Display them.

Input:

import pickle

s = ''' This is my first line.

This is my second line.'''

f = open("info.dat","wb")

pickle.dump(s,f)

f.close()

rec = {}

f = open("info.dat","rb")

try:

while True:

rec = pickle.load(f)

print(rec)

except EOFError:

f.close()

Output:
Practical-11

Question: Write a Program in Python to modify the data of a specific Employee in a Binary file
containing Employees Records

Input:

import pickle

f = open("emp.dat","ab")

emp_id = int(input("Enter the employee id :"))

emp_name = input("Enter the name of the employee :")

salary = int(input("Ente the salary of the employee :"))

rec = [emp_id,emp_name,salary]

pickle.dump(rec,f)

f.close()

Output:
Practical-12

Question: Write a Program to insert Records of 5 Students(Roll no, Name, Marks) in a CSV file.

Input:

import csv

f = open("stud.csv","w",newline="")

w = csv.writer(f)

w.writerow(['Rollno','Name','Marks'])

for i in range(5):

print("student_rec",(i+1))

Rollno = int(input("Enter the roll no of the student :"))

Name = input("Enter the name of the student :")

Marks = int(input("Enter the marks obtained by the student :"))

studrec = [Rollno,Name,Marks]

w.writerow(studrec)

f.close() Output:
Practical-13

Question: Write a program to insert Emp_ID, Name and salary of 5 Employees in a CSV file
“emp.csv”.

Input:

import csv

file1 = open("emp.csv","w",newline="")

w = csv.writer(file1)

w.writerow(['Emp_ID','Emp_name','Salary'])

for i in range(5):

print("Emp_Record",(i+1))

Emp_ID= int(input("Enter the Employee_ID :"))

Emp_Name = input("Enter the name of the Employee :")

Salary = int(input("Enter the salary of the Employee :"))

Emp_Record = [Emp_ID,Emp_Name,Salary]

w.writerow(Emp_Record)

file1.close()

Output:
Practical-14

Question: Write a Program in Python which adds any random five odd numbers in a list that
fall between the highest and the lowest number.

Input:

import random

List = []

highest_limit = int(input("Enter the highest limit :"))

lowest_limit = int(input("Enter the lowest limit :"))

while lowest_limit:

a = random.randrange(lowest_limit+1,highest_limit)

if a%2!=0:

List.append(a)

if len(List)==5:

break

print(List)

Output:
Practical-15

Question: Write a program in python to implement stack operations like push, pop, peek
using list.

Input:

def stack():

stack = []

while True:

print("\nStack Operations")

print(" Menu ")

print("1. Push")

print("2. Pop")

print("3. Peek")

print("4. Display")

print("5. Exit")

c = input("Enter your choice -->")

if c=="1":

item = input("Enter the item to push :")

stack.append(item)

print(f"{item} pushed to stack")

elif c=="2":

if stack:

print(f"{stack.pop()} popped from the stack")


else:

print("The Stack is empty")

elif c=="3":

if stack:

print(f"Top element of the stack is :{stack[-1]}")

else:

print("The stack is empty")

elif c=="4":

if stack:

print("Stack Elements are :- ",stack)

else:

print("The stack is empty")

elif c=="5":

break

else:

print("Invalid Choice")

stack()
Output:
Practical-16

Question: Consider table “emp1” with columns emp_id, emp_name, emp_dept, salary,
joining_date.

--Implement the following SQL commands on the table emp--

 List all employees with their department names.

 Find department wise total salary.

 Increase the salary of the employees by 10%.


 Insert a new record of an employee.

 Count the number of employee in each department.

Practical-17

Question: Consider the table “electronic_devices” with columns dev_id, dev_name,


dev_type, dev_brand, price.

--Implement the following SQL commands on the table electronic_devices—

 Display all the items whose price is greater than 50000.


 Display the names of all devices along with their brand in alphabetical order.

 Increase the price of all the devices by 5%.

 Count the number of devices made by each brand .


 Discount the price of all the devices by 10%

Practical-18

Question: Consider the table “result” with columns student_id, student_name,


student_marks, student_class, student_section.

--Implement the following SQL commands on the table result—

 Display the names of all the students who scored above 90 marks.
 Display the name of students in alphabetical order.

 Display the number of students in each section.

 Display the name of the student with highest and lowest marks.

 Find the average marks of all students.


Practical-19

Question: Consider the table “payment” with columns customer_id, customer_name,


amount, mode, payment date and

“paymentdue” with columns customer_id, customer_name, payment_due, due_date

--Implement the following SQL commands on the table payment and paymentdue—

 Display the sum of total amount paid by different mods.

 Display the name of customer where mode of payment is cash

 Create a report that summarize payment received and payment due .


 Display the all customers id and customer names in alphabetical order.

 Change the mode of payment to “debit card” where customer_id is 5.


Practical-20

Question: Consider the table “club” with columns coach_id, coach_name, age,
sports,date_of_app, salary,sex

--Implement the following SQL commands on the table club—

 Display the list of the coach who is playing karate.

 Display the name of the coach whose name starts with S.

 Display the total salary paid to coach gender wise.


 Select minimum age from the club where sex is “M”.

 Select average age from club group by sex.


Practical-21

Question: Write a program to connect MySQL database and create a table with
employee records.

Input:

import mysql.connector as ps

py = ps.connect(

host='localhost',

user='root',

password='ayush3306',

database='emp')

cr = py.cursor()

x = "create table employee(emp_id int(4),emp_name char(15),salary int(6),age


int(2));"

data = cr.execute(x)

Output:
Practical-22

Question: Write a program to insert data on the employee with user input.

Input:

import mysql.connector as ps

py = ps.connect(

host='localhost',

user='root',

password='ayush3306',

database='emp')

cr = py.cursor()

emp_id = int(input("Enter the employee id :"))

emp_name = input("Enter the name of the employee :")

salary = int(input("Enter the salary :"))

age = int(input("Enter the age :"))

x = "insert into employee(emp_id,emp_name,salary,age)


values({},'{}',{},{})".format(emp_id,emp_name,salary,age)

data = cr.execute(x)

py.commit()
Output:
Practical-23

Question: Write a program to display the names of employee whose salary is


greater than 80000

Input:

import mysql.connector as ps

py = ps.connect(

host='localhost',

user='root',

password='ayush3306',

database='emp')

cr = py.cursor()

x = ''' select emp_name

from emp1

where salary>80000'''

cr.execute(x)

data = cr.fetchall()

for i in data:

print(i)

py.commit()
Output:

Practical-24

Question: Write a program to increase the salary of the employees by 5%

Input:

import mysql.connector as ps

py = ps.connect(

host='localhost',

user='root',

password='ayush3306',

database='emp')

cr = py.cursor()

x = ''' update emp1

set salary=salary+salary*0.5'''

cr.execute(x)

py.commit()
Output:

You might also like