Atharva Rathod Practical Record
Atharva Rathod Practical Record
2. Simple Interest
def Interest(Principal, Rate, Time):
si = (Principal * Rate * Time) /
100 print("Simple Interest:", si)
3. Area of Circle
def areacircle(radius):
area = 3.14 * radius * radius
print("Area of Circle:", area)
4. Even or Odd
def EvenOdd(number):
if number % 2 == 0:
print("Even Number")
else:
print("Odd Number")
5. Maximum of Three
def Maximum(first, second, third):
if first >= second and first >= third:
print("Maximum:", first)
elif second >= first and second >= third:
print("Maximum:", second)
else:
print("Maximum:", third)
6. Count Uppercase & Lowercase
def Count(message):
u=l=0
for ch in message:
if ch.isupper():
u += 1
elif ch.islower():
l += 1
print("Uppercase:", u)
print("Lowercase:", l)
7. Factorial
def Factorial(number):
fact = 1
for i in range(1, number + 1):
fact *= i
print("Factorial:", fact)
8. Unique List
def UniqueList(lst, size):
unique = []
for x in lst:
if x not in unique:
unique.append(x)
return unique
def sumEven(lst):
return sum(x for x in lst if x % 2 == 0)
def sumOdd(lst):
return sum(x for x in lst if x % 2 != 0)
def menu1():
print("1. Check Even or Odd")
print("2. Sum of Even Numbers")
print("3. Sum of Odd Numbers")
ch = int(input("Enter choice: "))
lst = [1, 2, 3, 4, 5, 6]
if ch == 1:
n = int(input("Enter number: "))
print("Even" if isEven(n) else "Odd")
elif ch == 2:
print("Sum of Even:",
sumEven(lst)) elif ch == 3:
print("Sum of Odd:", sumOdd(lst))
def areaCircle(r):
return 3.14 * r * r
def areaSquare(s):
return s * s
def menu2():
print("1. Area of Rectangle")
print("2. Area of Circle")
print("3. Area of Square")
ch = int(input("Enter choice: "))
if ch == 1:
l = int(input("Length: "))
b = int(input("Breadth:
"))
print("Area:", areaRectangle(l, b))
elif ch == 2:
r = int(input("Radius: "))
print("Area:", areaCircle(r))
elif ch == 3:
s = int(input("Side: "))
print("Area:", areaSquare(s))
Text File Programs
1. Program to count occurrences of “Me” or “My” (case-insensitive) in MyData.txt
Write a function CountMeMy() in Python that counts how many times the words “Me” or “My”
(including lowercase) appear in MyData.txt.
def CountMeMy():
count = 0
with open("MyData.txt", "r") as f:
for word in f.read().split():
if word.lower() in ["me", "my"]:
count += 1
print("Count of 'Me' or 'My':", count)
def AMCount():
count = 0
with open("Story.txt", "r") as f:
for ch in f.read():
if ch.lower() in ["a", "m"]:
count += 1
print("Count of A or M:", count)
def CountLineA():
count = 0
with open("MyData.txt", "r") as f:
for line in f:
if line.strip().startswith("A"):
count += 1
print("Lines starting with A:", count)
4. Program to display words < 4 characters from Story.txt
Write a function DisplayWords() to show only those words having less than 4 characters.
def DisplayWords():
with open("Story.txt", "r") as f:
for line in f:
for word in line.split():
if len(word) < 4:
print(word)
def
CountUpperLower():
upper = lower = 0
with open("Story.txt", "r") as f:
for ch in f.read():
if
ch.isupper():
upper += 1
elif
ch.islower():
lower += 1
print("Uppercase:", upper)
print("Lowercase:", lower)
def CountM():
count = 0
with open("MyData.txt", "r") as f:
for line in f:
if line.strip().startswith(("I", "M")):
count += 1
print("Lines starting with I or M:", count)
7. Program to count lines starting with ‘H’ in Lines.txt
Write a function CountH() to count lines beginning with H.
def CountH():
count = 0
with open("Lines.txt", "r") as f:
for line in f:
if
line.strip().startswith("H"):
count += 1
print("Lines starting with H:", count)
def CountThe():
count = 0
with open("MyFile.txt", "r") as f:
for word in f.read().split():
if word.lower() == "the":
count += 1
print("Count of 'the':", count)
def CountHeShe():
count = 0
with open("MyFile.txt", "r") as f:
for word in f.read().split():
if word in ["He",
"She"]: count += 1
print("Count of He/She:", count)
def Display():
with open("MyNotes.txt", "r") as f:
for line in f:
if
line.strip().startswith("K"):
print(line, end="")
11. Program to count number of spaces in Data.txt
Write a function CountSpace() to count all spaces.
def CountSpace():
count = 0
with open("Data.txt", "r") as f:
for ch in f.read():
if ch == " ":
count += 1
print("Total spaces:", count)
def CountVowels():
vowels = "aeiou"
count = 0
with open("Data.txt", "r") as f:
for ch in f.read().lower():
if ch in vowels:
count += 1
print("Total vowels:", count)
def CopyContents():
with open("Data1.txt", "r") as f1, open("Data2.txt", "w") as f2:
for ch in f1.read():
if ch != " ":
f2.write(ch)
print("Copy complete (spaces removed).")
Binary File Programs
1. Program to Add Book Records and Count Books by Author
(Book.dat) AddRecords() adds records in the format [BookID,
BookName, Author, Price]. CountRec(author) counts books written
by the given author.
import pickle
def AddRecords():
f = open("Book.dat", "ab")
bookid = int(input("Enter Book
ID: ")) name = input("Enter Book
Name: ")) author = input("Enter
Author Name: ")) price =
float(input("Enter Price: "))
rec = [bookid, name, author,
price] pickle.dump(rec, f)
f.close()
print("Record added.")
def CountRec(author):
count =
0 try:
f = open("Book.dat",
"rb") while True:
rec = pickle.load(f)
if rec[2].lower() ==
author.lower(): count += 1
except:
pass
print("Books by", author, "=", count)
import pickle
def WriteRecords():
f = open("Employee.dat", "ab")
code = int(input("Enter Employee
Code: ")) name = input("Enter
Employee Name: ")) salary =
float(input("Enter Salary: "))
rec = [code, name,
salary]
pickle.dump(rec, f)
f.close()
print("Record added.")
def Search():
code = int(input("Enter Employee Code to Search:
")) found = False
try:
f = open("Employee.dat",
"rb") while True:
rec =
pickle.load(f) if
rec[0] == code:
print("Record Found:", rec)
found = True
except:
pass
if not found:
print("No matching record found.")
def Create():
f = open("Student.dat", "ab")
roll = int(input("Enter Roll
Number: ")) name = input("Enter
Name: ")
marks = float(input("Enter
Marks: ")) rec = [roll, name,
marks] pickle.dump(rec, f)
f.close()
print("Record added.")
def Display():
found =
False try:
f = open("Student.dat",
"rb") while True:
rec =
pickle.load(f) if
rec[2] > 81:
print(rec)
found =
True
except:
pass
if not found:
print("No Record Found")
4. Program to Add Bus Records and Search for Buses Going to Delhi (Bus.dat)
Insert() adds [BusNumber, StartingPlace,
DestinationPlace]. Search() prints buses whose
destination is “Delhi”.
import
pickle def
Insert():
f = open("Bus.dat", "ab")
bno = int(input("Enter Bus
Number: ")) start = input("Enter
Starting Place: ") dest =
input("Enter Destination: "))
rec = [bno, start,
dest]
pickle.dump(rec, f)
f.close()
print("Record added.")
def Search():
print("Buses going to
Delhi:") try:
f = open("Bus.dat",
"rb") while True:
rec = pickle.load(f)
if rec[2].lower() == "delhi":
print(rec)
excep
t:
pass
def Insert():
f = open("Route.dat", "ab")
rno = int(input("Enter Route
Number: ")) rname = input("Enter
Route Name: ")) rec = [rno,
rname]
pickle.dump(rec
, f) f.close()
print("Record added.")
def
RouteChange(routeno):
f = open("Route.dat",
"rb")
temp = open("Temp.dat",
"wb") found = False
try:
while True:
rec =
pickle.load(f) if
rec[0] ==
routeno:
rec[1] = input("Enter new Route
Name: ") found = True
pickle.dump(rec,
temp) except:
pass
f.close()
temp.close
()
os.remove("Route.dat")
os.rename("Temp.dat",
"Route.dat") if found:
print("Route
updated.") else:
print("Route number not found.")
6. Program to Add Employee Records and Display Salary > 20000 (Employee.dat)
Insert() adds [EmpID, EmpName, Salary].
Display() prints employees whose salary is more than
def Insert():
f = open("Employee.dat", "ab")
eid = int(input("Enter Employee ID:
")) name = input("Enter Employee
Name: ")) salary = float(input("Enter
Salary: "))
rec = [eid, name,
salary]
pickle.dump(rec, f)
f.close()
print("Record added.")
def Display():
print("Employees with Salary >
20000:") try:
f = open("Employee.dat",
"rb") while True:
rec =
pickle.load(f) if
rec[2] > 20000:
print(rec)
excep
t:
pass
7. Program to Add, Display, Search, Modify and Delete Room Records (Hotel.dat)
AddRecords() adds [RoomNo, RoomType,
Price]. Display() prints all hotel records.
SpecificRoom(roomno) searches for a
room. ModifyRoom(roomno) updates
room details. DeleteRoom(roomno)
removes a room.
import pickle,
os def
AddRecords():
f = open("Hotel.dat", "ab")
rno = int(input("Enter Room
Number: ")) rtype = input("Enter
Room Type: ")) price =
float(input("Enter Price: "))
rec = [rno, rtype,
price]
pickle.dump(rec, f)
f.close()
print("Record added.")
def Display():
try:
f = open("Hotel.dat",
"rb") while True:
print(pickle.load(f))
except:
pass
def
SpecificRoom(roomno):
found = False
try:
f = open("Hotel.dat",
"rb") while True:
rec =
pickle.load(f) if
rec[0] ==
roomno:
print(rec)
found =
True
except:
pass
if not found:
print("Room not
found.")
def
ModifyRoom(roomno):
f = open("Hotel.dat",
"rb")
temp = open("Temp.dat",
"wb") found = False
try:
while True:
rec = pickle.load(f)
if rec[0] == roomno:
rec[1] = input("Enter new Room
Type: ") rec[2] = float(input("Enter
new Price: ")) found = True
pickle.dump(rec,
temp) except:
pass
f.close()
temp.close
()
os.remove("Hotel.dat")
os.rename("Temp.dat",
"Hotel.dat") if found:
print("Room
modified.") else:
print("Room not found.")
def
DeleteRoom(roomno):
f = open("Hotel.dat",
"rb")
temp = open("Temp.dat",
"wb") found = False
try:
while True:
rec =
pickle.load(f) if
rec[0] !=
roomno:
pickle.dump(rec,
temp) else:
found =
True
except:
pass
f.close()
temp.close
()
os.remove("Hotel.dat")
os.rename("Temp.dat",
"Hotel.dat") if found:
print("Room
deleted.") else:
print("Room not found.")
os def Input():
f = open("Product.dat", "ab")
pid = int(input("Enter Product ID:
")) name = input("Enter Product
Name: "))
price = float(input("Enter Product
Price: ")) rec = [pid, name, price]
pickle.dump(rec
, f) f.close()
print("Record added.")
def
DeleteRecord(productid)
: f = open("Product.dat",
"rb")
temp = open("Temp.dat",
"wb") found = False
try:
while True:
rec = pickle.load(f)
if rec[0] !=
productid:
pickle.dump(rec,
temp) else:
found =
True
except:
pass
f.close()
temp.close
()
os.remove("Product.dat")
os.rename("Temp.dat",
"Product.dat") if found:
print("Record
deleted.") else:
print("Product ID not found.")
CSV File Programs
1. Program to Add Mobile Records and Read All from Mobile.csv
import
csv def
Input():
f = open('Mobile.csv','a',newline='')
w = csv.writer(f)
mid = input("Enter Mobile ID: ")
comp = input("Enter Mobile
Company: ") price = input("Enter
Price: ") w.writerow([mid, comp,
price])
f.close()
print("Record added.")
def ReadAll():
f=
open('Mobile.csv','r')
r = csv.reader(f)
for rec in r:
print(rec)
f.close()
import
csv def
Input():
f = open('Student.csv','a',newline='')
w = csv.writer(f)
adm = input("Enter
Admno: ") name =
input("Enter Name: ") clas
= input("Enter Class: ")
sec = input("Enter
Section: ") marks =
input("Enter Marks: ")
w.writerow([adm, name, clas, sec,
marks]) f.close()
print("Record added.")
def ReadAll():
f=
open('Student.csv','r'
) r = csv.reader(f)
for rec in r:
print(rec)
f.close()
import
csv def
Input():
f = open('Student.csv','a',newline='')
w = csv.writer(f)
adm = input("Enter
Admno: ") name =
input("Enter Name: ") clas
= input("Enter Class: ")
sec = input("Enter
Section: ") marks =
input("Enter Marks: ")
w.writerow([adm, name, clas, sec,
marks]) f.close()
print("Record added.")
def Search(admno):
f=
open('Student.csv','r'
) r = csv.reader(f)
found =
False for rec
in r:
if rec[0] ==
admno: print(rec)
found =
True if not
found:
print("Record not found")
f.close()
import csv
def Input():
f=
open('Product.csv','a',newline=
'') w = csv.writer(f)
pid = input("Enter Product ID: ")
name = input("Enter Product
Name: ") price = input("Enter
Price: ") w.writerow([pid, name,
price]) f.close()
print("Record added.")
def
SearchProduct(price):
f =
open('Product.csv','r')
r = csv.reader(f)
for rec in r:
if int(rec[2]) >
price: print(rec)
f.close()
import
csv def
Input():
f = open('Student.csv','a',newline='')
w = csv.writer(f)
adm = input("Enter
Admno: ") name =
input("Enter Name: ") clas
= input("Enter Class: ")
sec = input("Enter
Section: ") marks =
input("Enter Marks: ")
w.writerow([adm, name, clas, sec,
marks]) f.close()
print("Record added.")
def SearchRecord():
f=
open('Student.csv','r'
) r = csv.reader(f)
for rec in r:
if int(rec[4]) >
80: print(rec)
f.close()
6. Program to Add Product Records and Search by Product Name “Scanner”
import
csv def
Input():
f = open('Product.csv','a',newline='')
w = csv.writer(f)
pid = input("Enter Product ID: ")
name = input("Enter Product
Name: ") price = input("Enter
Price: ") w.writerow([pid, name,
price]) f.close()
print("Record added.")
def SearchRecord():
f=
open('Product.csv','r')
r = csv.reader(f)
for rec in r:
if rec[1].lower() ==
"scanner": print(rec)
f.close()
Data Structure Problems
1. Program to Push and Pop Student Names in a Stack
student = []
def push(studentname):
student.append(studentname)
print(f"{studentname} added to the
stack.")
def pop():
if len(student) == 0:
print("Stack is
empty") else:
removed = student.pop()
print(f"{removed} removed from the stack.")
def PushOn(BookTitle):
Books.append(BookTitle)
print(f"'{BookTitle}' added to the
stack.")
def Pop():
if len(Books) == 0:
print("Stack is
empty") else:
removed = Books.pop()
print(f"'{removed}' removed from the stack.")
def insert():
bid = input("Enter Book ID: ")
name = input("Enter Book
Name: ") Book.append([bid,
name]) print("Book added to
stack.")
def delete():
if len(Book) == 0:
print("Stack is
empty") else:
removed = Book.pop()
print(f"Removed Book:
{removed}")
def show():
if len(Book) == 0:
print("Stack is
empty") else:
for b in reversed(Book):
print(b)
Student =
[] def
insert():
roll = input("Enter Roll No: ")
name = input("Enter Name:
") Student.append([roll,
name]) print("Student
added to stack.")
def delete():
if len(Student) ==
0: print("Stack is
empty") else:
removed = Student.pop()
print(f"Removed Student:
{removed}")
def show():
if len(Student) == 0:
print("Stack is empty")
else:
for s in reversed(Student):
print(s)
HostelStack =
[] def
addRecord():
hid = input("Enter Hostel ID: ")
totalStud = input("Enter Total Students: ")
totalRooms = input("Enter Total Rooms: ")
HostelStack.append([hid, totalStud,
totalRooms]) print("Hostel record added.")
def deleteRecord():
if len(HostelStack) ==
0: print("Stack is
empty") else:
removed = HostelStack.pop()
print(f"Removed record:
{removed}")
def showRecords():
if len(HostelStack) ==
0: print("Stack is
empty") else:
for rec in
reversed(HostelStack):
print(rec)
MySQL Problems
1. Shop Table
(a) Question:
Display names of items starting with 'C' in ascending order of price.
Answer:
SQL Command:
SELECT ItemName FROM Shopee WHERE ItemName LIKE 'C%' ORDER BY Price
ASC;
Output:
ItemNam
e Cake
Coffee
Chocolat
e
(b)Question:
Display code, itemname, and city of items with quantity less than 100.
Answer:
SQL Command:
SELECT Code, ItemName, City FROM Shopee WHERE Qty < 100;
Output:
Code ItemName City
106Sauce Mumbai
107Cake Delhi
(c) Question:
Count the number of distinct companies.
Answer:
SQL Command:
SELECT COUNT(DISTINCT Company) FROM Shopee;
Outpu
t: 5
(d)Question:
Insert a new row: 108, 'Tea', 'Tata', 80, 'Delhi', 15.00
Answer:
SQL Command:
INSERT INTO Shopee VALUES (108, 'Tea', 'Tata', 80, 'Delhi', 15.00);
(e)Question:
Select itemname for items 'Jam' or 'Coffee'.
Answer:
SQL Command:
SELECT ItemName FROM Shopee WHERE ItemName IN ('Jam', 'Coffee');
Output:
ItemNam
e Jam
Coffee
(f)Question:
Count distinct cities.
Answer:
SQL Command:
SELECT COUNT(DISTINCT City) FROM Shopee;
Outpu
t: 3
(g)Question:
Find minimum quantity for items in Mumbai.
Answer:
SQL Command:
SELECT MIN(Qty) FROM Shopee WHERE City='Mumbai';
Output:
56
2. Employee Table
(a) Question:
Display names of all employees who are in area South.
Answer:
SQL Command:
SELECT Name FROM Employee WHERE Area='South';
Output
:
Name
Akash
Cheta
n
(b)Question:
Display name and age of all employees having age > 40.
Answer:
SQL Command:
SELECT Name, Age FROM Employee WHERE Age > 40;
Output:
Name
Age
Vinay 45
Yogesh 52
(c) Question:
Display list of all employees whose salary is between 30000 and 40000.
Answer:
SQL Command:
SELECT * FROM Employee WHERE Salary >= 30000 AND Salary <= 40000;
Output:
S.No Name Salary Area Age Grade Dept
1 Vinay 40000 West 45 C Civil
2 Akash 35000 South 38 A Elec
4 Monesh 38000 North 29 B Civil
(d)Question:
Display the list department-wise.
Answer:
SQL Command:
SELECT * FROM Employee ORDER BY Dept;
Output:
S.No Name Salary Area Age Grade
Dept 1 Vinay 40000 West 45 C Civil
3 Yogesh 60000 North 52 B Civil
4 Monesh 38000 North 29 B Civil
6 Chetan 29000 South 34 A Mech
5 Simarjeet 42000 East 35 A Comp
2 Akash 35000 South 38 A Elec
(e)Question:
Display employee names in descending order of age.
Answer:
SQL Command:
SELECT Name FROM Employee ORDER BY Age DESC;
Output
:
Name
Yoges
h
Vinay
Simarje
et
Akash
Chetan
Monesh
(f)Question:
Insert a new row with the following data:
7, “Tarak”, 45000, “South”, 45, “C”, “Elec”
Answer:
SQL Command:
INSERT INTO Employee VALUES (7, 'Tarak', 45000, 'South', 45, 'C', 'Elec');
Output:
Row added successfully (no visible output).
(g)Question:
Write the output of the following SQL commands:
(a) Question:
Display names of students who are getting grade “C” in either Game or SUPW.
Answer:
SQL Command:
SELECT Name FROM Student WHERE Grade='C' OR Sgrade='C';
Output:
Nam
e
Veen
a
Sujit
Arpit
(b) Question:
Display the number of students getting grade “A” in Cricket.
Answer:
SQL Command:
SELECT COUNT(*) FROM Student WHERE Game='Cricket' AND Grade='A';
Output:
Coun
t1
(c) Question:
Display the different games offered in the school.
Answer:
SQL Command:
SELECT DISTINCT Game FROM Student;
Output:
Game
Cricket
Tennis
Swimmin
g Basket
Ball
(d) Question:
Display the SUPW taken up by the students whose name starts with “A”.
Answer:
SQL Command:
SELECT SUPW FROM Student WHERE Name LIKE 'A%';
Output:
SUPW
Literatur
e
Gardenin
g
(e) Question:
Add a new column named “Marks” in the Student table.
Answer:
SQL Command:
ALTER TABLE Student ADD Marks INT;
Output:
Column added successfully (no visible output).
(f) Question:
Assign a value 200 for marks for all those who are getting grade “B” or above in
Game.
Answer:
SQL Command:
UPDATE Student SET Marks=200 WHERE Grade IN ('A','B');
Output:
Rows updated successfully (no visible output).
(g) Question:
Arrange the table in alphabetical order of SUPW.
Answer:
SQL Command:
SELECT * FROM Student ORDER BY SUPW ASC;
Output:
StdNo Clas Name Game Grade SUPW Sgrad Marks
s e
Output:
7 Ankita 29 Cardiology 20/02/98 800 F
9 Kush 19 Cardiology 13/01/98 800 M
Output:
(No results)
(c) List names of all patients with their date of admission in ascending order
Output:
4 Tarun 01/01/98
5 Zubin 12/01/98
9 Kush 13/01/98
2 Ravina 20/01/98
7 Ankita 20/02/98
10 Shailya 19/02/98
3 Karan 19/02/98
8 Zareen 22/02/98
1 Sandeep 23/02/98
6 Ketika 24/02/98
Output:
1 Sandeep 300 65
3 Karan 200 45
4 Tarun 300 12
5 Zubin 250 36
9 Kush 800 19
10 Shailya 400 31
Outpu
t: 7
(f) Insert new row: 11, Mustafa, 37, ENT, 25/02/98, 250, M
Output:
Deepak 35 8000
Gitika 22 7000
Varun 54 6000
(b)To display Mcode, Mname, Age of all female members in ascending order of
age.
Output:
3 Gitika 22
7 Farida 22
4 Pallavi 27
6 Prerna 43
(c) To display Mname, Age, Type of all members in ascending order of Mname.
Output:
Deepak 35 Monthly
Farida 22 Guest
Gitika 22 Monthly
Harshit 32 Quarterly
Jatin 51 Yearly
Pallavi 27 Quarterly
Pratyush 45 Yearly
Prerna 43 Monthly
Rakshit 44 Life
Varun 54 Monthly
(d)To display Mname, Fees of all members whose Age < 40 and Type =
“Monthly”.
Output:
Deepak
8000
Gitika 7000
(f)Output queries:
Salary Table
Empid Salary Benefits Designation
Output:
Sam Tones 33 Elm Street Paris
Peter Thompson 11 Red Road
Paris
Output:
Sam Tones 33 Elm Street Paris
Sarah Ackerman 440 U S 110
Upton
Rabert Samuel 9 Fifth Cross
Washington Peter Thompson 11 Red
Road Paris Rachel Lee 12 Harrson
Street New York Mary Jones 842 Vine
Ave Losantiville
Manila Sengupta 24 Friends Street New
Delhi Henry Williams 12 Moore Street
Boston George Smith 83 First Street
Howard
(c) Display firstname, lastname, and total salary of all managers (Total Salary
= Salary + Benefits).
Output:
George Smith 90000
Mary Jones 80000
Sarah Ackerman 87500
Output:
Manager:
75000
Clerk: 50000
Output:
Rachel
32000
Peter 28000
(f)Select count(distinct Designation) from EmpSalary.
Output: 4
Output:
Manager 215000
Clerk 135000
Output: 32000
7. Stock Table
Dealer Table
Dcode Dname
101 Reliable
Stationers
102 Clear Deals
Output:
5006 Gel Pen Classic 101 200 22 01/01/2009
5001 Eraser Small 102 210 5 19/03/2009
5004 Eraser Big 102 60 10 12/12/2009
5003 Ball Pen 0.25 102 150 20 01/01/2010
5002 Gel Pen Premium 101 125 14 14/02/2010
5005 Ball Pen 0.5 102 100 16 31/03/2010
5009 Sharpener Classic 103 160 8 23/01/2009
(b)Display ItemNo and Item Name of items with UnitPrice > 10.
Output:
5005 Ball Pen 0.5
5003 Ball Pen 0.25
5002 Gel Pen
Premium 5006 Gel
Pen Classic
(c) Display details of items whose dealer code = 102 or Qty > 100.
Output:
5005 Ball Pen 0.5 102 100 16 31/03/2010
5003 Ball Pen 0.25 102 150 20 01/01/2010
5002 Gel Pen Premium 101 125 14 14/02/2010
5001 Eraser Small 102 210 5 19/03/2009
5006 Gel Pen Classic 101 200 22 01/01/2009
Output:
101 22
102 20
103 8
STOCK. Output: 3
Output: 4400
Output:
Eraser Big Clear Deals
(h)Minimum StockDate in
Sender Table
Recipient Table
Output:
K005 R Jain 2 ABC Appts R Bajpayee 5 Central Avenue
ND08 H Sinha 12 Newton S Mahajan 116 A Vihar
MU19 R Jain 2 ABC Appts H Singh 2A, Andheri East
MU32 S Jha 27/A, Park Street P K Swamy B5 C S Terminus
ND48 T Prasad 122-K, SDA S Tripathi 13, B1 D, Mayur
Vihar
Output:
K005 R Bajpayee 5 Central
Avenue ND08 S Mahajan 116 A
Vihar MU19 H Singh 2A,
Andheri East
MU32 P K Swamy B5 C S Terminus
ND48 S Tripathi 13, B1 D, Mayur
Vihar
Output:
Kolkata
1
New Delhi 2
Mumbai 2
Output:
New
Delhi
Mumbai
Output:
R Jain H Singh
S Jha P K Swamy
Output:
S Mahajan 116 A Vihar
S Tripathi 13, B1 D, Mayur Vihar
Output:
ND08 S Mahajan
ND48 S Tripathi
9. Products Table
8 Printer 7900 HP 10
(a) Display data for the entire item sorted by their name.
Output:
CD ROM 2800 Creative 32
Keyboard 1000 TVSE 70
Monitor 3000 Philips 22
Motherboard 7000 Intel 20
Mouse 500 Logitech 60
Printer 7900 HP 10
Soundcard 600 Samsung 50
Speaker 600 Samsung 25
(b)Display Name and Price from the table in reverse order of Stock.
Output:
Keyboard
1000
Mouse 500
Soundcard 600
Speaker 600
CD ROM 2800
Monitor 3000
Motherboard 7000
Printer 7900
(c) List all Name and Price with Price between 3000 and 7000.
Output:
Monitor
3000
Motherboard 7000
(d)Set the price field of all products to 1200 where Name = 'Keyboard'.
Output:
Keyboard 1200 TVSE 70
Output:
Deleted rows: CD ROM, Motherboard, Monitor, Speaker
Outpu
t: 0
(a) Display the names of all shops which are in the area South.
Output:
Dharoh
ar
Crystal
Output:
Dharohar
81.8
Ripple 88.0
Biswas Stores 92.0
(c) Display a list of all shops with sale>300000 in ascending order of Shop_Name.
Output:
Biswas Stores 456000
Dharohar 500000
Ripple 380000
(d)Display a report with Shop_Name, Area and Rating for only those shops
whose sale is between 350000 and 400000.
Output:
Ripple North B
(e)Display the city and the number of shops in each city.
Outpu
t:
Delhi
2
Mumbai 2
Kolkata 2
(f)Insert details of a new shop with the following data: 7, 'The Shop', 550000,
'South', 90.8, 'A', 'Ahmedabad'.
Output:
Shop inserted: The Shop, 550000, South, 90.8, A, Ahmedabad
Employee Table
EmpID EmpName City Department Salary
import mysql.connector
conn =
mysql.connector.connect( h
ost="localhost",
user="root",
password="your_passwor
d", database="Office"
)
cursor = conn.cursor()
cursor.close()
conn.close(
)
Problem 2: Display employee details for EmpID = 1003
import mysql.connector
conn =
mysql.connector.connect( h
ost="localhost",
user="root",
password="your_passwor
d", database="Office"
)
cursor = conn.cursor()
emp_id = 1003
cursor.execute("SELECT * FROM EmpInfo WHERE EmpID = %s",
(emp_id,)) rows = cursor.fetchall()
cursor.close
()
conn.close(
)
Items Table
1001 Bread 25 20 10
1002 Butter 50 15 7
1003 Milk 60 25 10
conn =
mysql.connector.connect( h
ost="localhost",
user="root",
password="your_passwor
d", database="Shops"
)
cursor = conn.cursor()
print(f"Number of records:
{len(rows)}") cursor.close()
conn.close()
import mysql.connector
conn =
mysql.connector.connect( h
ost="localhost",
user="root",
password="your_passwor
d", database="Shops"
)
cursor = conn.cursor()
item_no = 1003
cursor.execute("DELETE FROM Items WHERE ItemNo = %s",
(item_no,)) conn.commit()
cursor.close()
conn.close(
)
Problem 5: Update ItemPrice for ItemNo = 1004 and display all
import mysql.connector
conn =
mysql.connector.connect( h
ost="localhost",
user="root",
password="your_passwor
d", database="Shops"
)
cursor = conn.cursor()
item_no = 1004
new_price = 150
cursor.execute("UPDATE Items SET ItemPrice = %s WHERE ItemNo = %s",
(new_price, item_no))
conn.commit()
cursor.close()
conn.close(
)