Wa0012
Wa0012
(A). To write a Python program that reads a text file and displays the number of vowels and
consonants in the file.
def text(file_name):
file = open(file_name, 'r')
text = file.read()
file.close()
space_count = 0
digit_count = 0
lowercase_count = 0
uppercase_count = 0
total_characters = 0
(B) Consider the tables Product and write SQL commands for questions (1) to (4).
TABLE : PRODUCTS
1. Display product Id, product name, manufacturer for Body wash products.
Sql commands:
1. SELECT product_id, product_name, manufacturer FROM Products WHERE
product_category = 'Body Wash';
2. UPDATE Products SET price = price + 20 WHERE product_name = 'Conditioner';
3. SELECT manufacturer, AVG(price) AS “average_price” FROM Products GROUP BY
manufacturer;
4. DELETE FROM Products WHERE manufacturer = 'ORI';
Q2.
(A)
Write a Python program that prompts the user to input a username and password, stores them in
a CSV file, and allows the user to search for a username to display the corresponding password
if found.
import csv
def add_user(file_name='users.csv'):
username = input("Enter username: ")
password = input("Enter password: ")
file = open(file_name, mode='a', newline='')
writer = csv.writer(file)
writer.writerow([username, password])
file.close()
print("User '" + username + "' added successfully!")
def search_user(file_name='users.csv'):
username = input("Enter username to search: ")
file = open(file_name, mode='r')
reader = csv.reader(file)
for row in reader:
if row[0] == username:
print("Username: " + row[0] + ", Password: " + row[1])
file.close()
return
file.close()
print("Username '" + username + "' not found.")
add_user()
search_user()
Q2.
(B)
Write a program to create a student table and insert data. Write SQL commands for questions
(1) to (4).
Sql commands:
1. SELECT *FROM Students WHERE department = 'History';
2. SELECT name FROM Students WHERE department = 'Computer' AND gender =
'Female';
3. SELECT department, AVG(fees) AS average_fees FROM Students GROUP BY
department;
4. DELETE FROM Students WHERE gender = 'Male';
Q3.
(A) To create a python program that stores student names, department and roll numbers in a
binary file, and searches for a student by roll number, displaying the student's details if found.
import pickle
def write_in_file():
for i in range(no):
student = {}
pickle.dump(student, file)
file.close()
def display():
while True:
try:
stud = pickle.load(file)
print(stud)
except:
break
file.close()
def search():
while True:
try:
data = pickle.load(file)
if data["roll"] == r:
print(data)
found = True
break
except:
break
if not found:
file.close()
while True:
if ch == 1:
write_in_file()
elif ch == 2:
display()
elif ch == 3:
search()
elif ch == 4:
print("Thank you")
break
else:
Sql commands:
def read_from_file(file_name):
file = open(file_name, 'r')
content = file.read()
file.close()
print("Data read from " + file_name + ":\n" + content)
file_name = 'sample.txt'
write_to_file(file_name)
read_from_file(file_name)
Q4.
(B) Consider the tables Clients and write SQL commands for questions (1) to (4).
TABLE: CLIENTS
Sql Commands:
def pop(stk):
if isEmpty(stk):
print("UNDERFLOW CONDITION")
else:
print("Deleted element:", stk.pop())
def peek(stk):
return stk[-1]
def display(stk):
if isEmpty(stk):
print("No Element Present")
else:
for i in range(-1, -len(stk) - 1, -1):
if i == -1:
print("TOP", stk[i])
else:
print(" ", stk[i])
stk = []
while True:
print("Stack operations")
print("1.PUSH")
print("2.POP")
print("3.PEEK")
print("4.DISPLAY STACK")
print("5.EXIT")
ch = int(input("Enter the choice:"))
if ch == 1:
n = input("Enter the element to PUSH:")
push(stk, n)
print("Element pushed")
elif ch == 2:
pop(stk)
elif ch == 3:
if isEmpty(stk):
print("UNDERFLOW CONDITION")
else:
print(peek(stk))
elif ch == 4:
display(stk)
elif ch == 5:
break
else:
print("INVALID CHOICE ENTERED")
print("THANKS FOR USING MY SERVICES")
Q5.
(B) Consider the tables Clients and write SQL commands for questions (1) to (4).
TABLE: Employee
Sql Commands: