0% found this document useful (0 votes)
27 views12 pages

Wa0012

The document contains various programming tasks and SQL commands. It includes Python programs for text file manipulation, user authentication, and stack operations, as well as SQL queries for managing product, student, worker, client, and employee tables. Each section outlines specific requirements and provides code examples or SQL commands to fulfill them.
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)
27 views12 pages

Wa0012

The document contains various programming tasks and SQL commands. It includes Python programs for text file manipulation, user authentication, and stack operations, as well as SQL queries for managing product, student, worker, client, and employee tables. Each section outlines specific requirements and provides code examples or SQL commands to fulfill them.
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/ 12

Q1

(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

for char in text:


total_characters += 1
if char.isspace():
space_count += 1
elif char.isdigit():
digit_count += 1
elif char.islower():
lowercase_count += 1
elif char.isupper():
uppercase_count += 1

print("Number of spaces: ", space_count)


print("Number of digits: ", digit_count)
print("Number of lowercase letters: ", lowercase_count)
print("Number of uppercase letters: ", uppercase_count)
print("Total characters: ", total_characters)
text('Sample.txt')
Q1.

(B) Consider the tables Product and write SQL commands for questions (1) to (4).

TABLE : PRODUCTS

P_ID PRODUCTNAME MANUFACTURER PRICE

RP01 ROSE POWDER LAK 40

BW05 BODY WASH HIM 45

MC01 MOISTURIZING CREAM HIM 75

CO06 CONDITIONER REV 120

BW12 BODY WASH ORI 95

1. Display product Id, product name, manufacturer for Body wash products.

2. To increase the price of Conditioner by 20.

3. List the average price of products of each manufacturer.

4. Remove details of product which are manufactured by the manufacturer ORI.

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).

ROLL_N O STD_NAME AGE DEPT DATEOFADM FEE GENDER


1 PANKAJ 24 COMPUTER 1997/01/10 120 M
2 SHALINI 21 HISTORY 1998/03/24 200 F
3 SANJAY 22 HINDI 1996/12/12 300 M
4 SUDHA 25 HISTORY 1999/07/01 400 F
5 KAYAL 22 COMPUTER 1997/09/05 250 F

1. Display all the details about students in the History department.


2. Display the name of female students who are in the computer department.
3. Display average fees department wise.
4. Remove the details of male students.

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():

file = open("stud2.dat", "ab")

no = int(input("ENTER NO OF STUDENTS: "))

for i in range(no):

print("Enter details of student ", i+1)

student = {}

student["roll"] = int(input("Enter roll number: "))

student["name"] = input("Enter the name: ")

student["department"] = input("Enter the department: ")

pickle.dump(student, file)

file.close()

def display():

file = open("stud2.dat", "rb")

while True:

try:

stud = pickle.load(file)

print(stud)

except:

break

file.close()

def search():

file = open("stud2.dat", "rb")

r = int(input("Enter the roll number to search: "))


found = False

while True:

try:

data = pickle.load(file)

if data["roll"] == r:

print("The roll number =", r, " record found")

print(data)

found = True

break

except:

break

if not found:

print("The roll number =", r, " record is not found")

file.close()

while True:

print("MENU \n 1-Write in a file \n 2-Display \n 3-Search \n 4-Exit")

ch = int(input("Enter your choice = "))

if ch == 1:

write_in_file()

elif ch == 2:

display()

elif ch == 3:

search()

elif ch == 4:

print("Thank you")

break

else:

print("Invalid choice! Please try again.")


Q3.
(B). Consider the table Workers and write SQL commands for questions (1) to (4).
TABLE: WORKERS

W_ID FIRSTNAME LASTNAME ADDRESS CITY


102 SAM TONERS 33 ELM ST PARIS
105 SARAH ACKERMAN 440 U S NEW YORK
144 MANILA SENGUPTA 24 FRIENDS ST HOWARD
200 GEORGE SMITH 83 FIRST ST WASHINGTON
210 ROBERT SAMUEL 9 FIFTH CROSS BOSTON
450 PAT THOMSON 11 RED ROAD PARIS

1. Display names and addresses of all the employees


2. Display the names and city of employees who are from city Paris.
3. Display details of employees who ever First name begin with letter ‘’S”.
4. Remove details of employee 450.

Sql commands:

1. SELECT name, address FROM workers;


2. SELECT name, city FROM workers WHERE city = 'Paris';
3. SELECT * FROM workers WHERE first_name LIKE 'S%';
4. DELETE FROM workers WHERE employee_id = 450;
Q4.
(A) Write a Python program that takes a message from the user, writes it to a text file, and then
reads and displays the content of the file.
def write_to_file(file_name):
text = input("Enter the text to write to the file: ")
file = open(file_name, 'w')
file.write(text)
file.close()
print("Data written to " + file_name)

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

C_ID CLIENTNAME CITY P_ID


1 COSMETIC SHOP KOLKATA BW05
6 TOTAL HEALTH MUMBAI MC01
12 LIVE LIFE KOLKATA CO06
15 PRETTY WOMAN KOLKATA BW12
16 DREAMS BANGALORE RP01
1. Display client name, city for the client id 15.
2. Display the client’s name in ascending order.
3. Change city of client 12 into DELHI.
4. Remove details of client those who are from the city MUMBAI.

Sql Commands:

1. SELECT client_name, city FROM Clients WHERE client_id = 15;


2. SELECT client_name FROM Clients ORDER BY client_name ASC;
3. UPDATE Clients SET city = 'DELHI' WHERE client_id = 12;
4. DELETE FROM Clients WHERE city = 'MUMBAI';
Q5.
(A) To design a menu-driven Python program that demonstrates basic operations on a stack,
including push, pop, display, and checking if the stack is empty.
def isEmpty(stk):
if len(stk) == 0:
return True
else:
return False

def push(stk, n):


stk.append(n)

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

EMPNO ENAME JOB SALARY CITY


7369 SUNITHA CLERK 18000 KOLKATA
7499 ASHOK SALESMAN 36000 MUMBAI
7566 MARTIN MANAGER 49500 KOLKATA
7698 SURIYA MANAGER 47000 KOLKATA
7845 KARTHI SALESMAN 33500 BANGALORE
7477 DEV ANALYST 38000 MUMBAI

1. Display maximum salary of an employee.


2. Display employee details in the increasing order of their salary.
3. Change the city to 'Chennai' for the employee with empid = 7698 in the employee table.
4. Write a query to delete table from database.

Sql Commands:

1. SELECT MAX(salary) AS “max_salary” FROM employee;


2. SELECT * FROM employee ORDER BY salary ASC;
3. UPDATE employee SET city = 'Chennai' WHERE empid = 7698;
4. DROP TABLE employee;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy