python-mysql_practice_questions
python-mysql_practice_questions
1A) Write a menu driven program to perform the following tasks on a text file:
Ans:
i)def count_vowels():
f=open("file.txt")
count=0
dat=f.read()
for i in dat:
if i.lower() in "aeiou":
count+=1
f=open("file.txt")
data=f.read()
def count_capital():
f=open("file.txt")
count=0
dat=f.read().split()
for i in dat:
if i.isupper():
count+=1
else:
pass
def display():
f=open("file.txt","r")
data=f.read()
print(data)
while True:
print("__Menu__")
ch=int(input("Enter choice"))
if ch==1:
count_characters()
elif ch==2:
count_vowels()
elif ch==3:
count_capital()
elif ch==4:
display()
else:
break
1B) Write a menu-based program that adds an employee record containing the employee code,
employee name, department, salary, and manager and writes it to a csv file “Employee.csv”. The
program should also allow searching for an employee based on their employee code and display
their details.
Ans:
def add_record():
a = []
pen = csv.writer(f)
while True:
man = input("Manager:")
a.append(l)
if ch.lower() == "n":
break
pen.writerows(a)
def search(a):
found = False
dat = csv.reader(f)
for i in dat:
if int(i[0]) == a:
print(i)
found = True
break
if not found:
def display():
f=open("pass.csv","r")
data=csv.reader(f)
for i in data:
print(i)
while True:
print("_Menu_")
if ch == 1:
add_record()
elif ch == 2:
search(emcode)
elif ch==3:
display()
else:
break
1C) write a menu driven programme that creates a binary file "Employee.dat" containing the
following [Epno,Epname,city] . Use this to ask the user for a employee number and delete that
record.
Ans:
import pickle
def add_data():
f=open("Employee.dat","wb")
a=[]
while True:
city=input("Enter City:")
l=[Epno,Epname,city]
a.append(l)
if ch== "n":
break
else:
continue
pickle.dump(a,f)
f.close()
def Del(a):
f=open("Employee.dat","rb+")
n=a
l1=[]
try:
while True:
dat=pickle.load(f)
for i in dat:
if i[0]==n:
pass
else:
l1.append(i)
except:
f.close()
f=open("Employee.dat","wb+")
f.seek(0)
pickle.dump(l1,f)
f.close()
def display():
f=open("Employee.dat","rb")
try:
data=pickle.load(f)
print(data)
except:
f.close()
while True:
print("__Menu__")
ch=int(input("Enter choice"))
if ch==1:
add_data()
elif ch==2:
Del(emno)
Elif ch==3:
display()
else:
break
Ans:
stack=[]
def push(x):
stack.append(x)
def pop():
if len(stack)==0:
print("Empty Stack")
else:
stack.pop()
def display():
if len(stack)==0:
print("Empty Stack")
else:
for i in stack[::-1]:
print(i)
def peek():
print(stack[-1])
while True:
print("Menu\n1.Push\n2.Pop\n3.Display\n4.Peek")
if ch==1:
n=int(input("enter any no.:"))
push(n)
elif ch==2:
pop()
elif ch==3:
display()
elif ch==4:
peek()
else:
break
To create both tables and perform the given sql queries
Customer Table:
Company table:
A3)Decrease the price by 1000 for customer whose name ends with “n”. Also display the
updated customer list
A4)Display the city name and the number of records in each city
B1)Display the company names where price is less than 30000
B2)Find the customber name and company product where the price is between 20,000 and
40,000
3D)Increase the price by 100 for customers whose name contains ‘H’. Also
display the updated customer table.
4D) Display the city name and the number of records in each city.