0% found this document useful (0 votes)
2 views2 pages

SET9

The document contains a Python program that allows users to write data to a file, read data from it, and count the total lines present. It includes a menu-driven interface for user interaction. Additionally, it presents SQL commands to create tables for a car rental system and perform various queries on the data.

Uploaded by

shivambharti0922
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

SET9

The document contains a Python program that allows users to write data to a file, read data from it, and count the total lines present. It includes a menu-driven interface for user interaction. Additionally, it presents SQL commands to create tables for a car rental system and perform various queries on the data.

Uploaded by

shivambharti0922
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Q1.

def display_menu():
print("Menu:")
print("a. Write into file")
print("b. Read all data from file")
print("c. Count and show total lines present in file")
print("d. Exit")

def write_into_file():
with open('data.txt', "a") as fo:
data = input("Enter data to write into file: ")
fo.write(data + "\n")
print("Data written to file successfully.\n")

def read_all_data():
try:
with open('data.txt', "r") as file:
content = file.read()
print("Data in file:")
print(content)
except FileNotFoundError:
print("File not found.\n")

def count_lines():
try:
with open('data.txt', "r") as fo:
lines = fo.readlines()
total_lines = len(lines)
print(f"Total lines present in file: {total_lines}\n")
except FileNotFoundError:
print("File not found.\n")

def main():
while True:
display_menu()
choice = input("Enter your choice (a-d): ")
if choice == 'a':
write_into_file()
elif choice == 'b':
read_all_data()
elif choice == 'c':
count_lines()
elif choice == 'd':
print("Exiting program.")
break
else:
print("Invalid choice. Please try again.\n")
main()

A1.
Menu:
a. Write into file
b. Read all data from file
c. Count and show total lines present in file
d. Exit
Enter your choice (a-d): a
Enter data to write into file: I have learned over the years that when one’s mind is made up, this diminishes
fear.
Data written to file successfully.

Menu:
a. Write into file
b. Read all data from file
c. Count and show total lines present in file
d. Exit
Enter your choice (a-d): b
Data in file:
I have learned over the years that when one’s mind is made up, this diminishes fear.
Menu:
a. Write into file
b. Read all data from file
c. Count and show total lines present in file
d. Exit
Enter your choice (a-d): c
Total lines present in file: 1

Menu:
a. Write into file
b. Read all data from file
c. Count and show total lines present in file
d. Exit
Enter your choice (a-d): d
Exiting program.

Q2.
create table CARDEN(
Ccode int,
CarName varchar(20),
Make varchar(20),
Colour varchar(20),
Capacity int,
Charges int
);
create table CUSTOMER(
Code int,
Cname varchar(20),
Ccode int
);

Insert into CARDEN values (501,’A-Star’,’Suzuki’,’RED’,3,14);


Insert into CARDEN values (503,’Indigo’,’Tata’,’SILVER’,3,12);
Insert into CARDEN values (502,’Innova’,’Toyota’,’WHITE’,7,15);
Insert into CARDEN values (509,’SX4’,’Suzuki’,’SILVER’,4,14);
Insert into CARDEN values (510,’C Class’,’Mercedes’,’RED’,4,35);
Insert into CUSTOMER values (1001,’Hernant Sahu’,501);
Insert into CUSTOMER values (1002,’Raj Lal’,509);
Insert into CUSTOMER values (1003,’Feroza Shah’,503);
Insert into CUSTOMER values (1004,’Ketan Dhal’,502);

i. select CARNAME from CARDEN where Colour = 'SILVER';


ii. select CARNAME,MAKE, CAPACITY from CARDEN order by CAPACITY desc;
iii. select max(CHARGES) from CARDEN;
iv. select CNAME, CARNAME from CARDEN natural join CUSTOMER;

You might also like