source code
source code
Text file:
def copylines():
f = open("tfile.txt",'r')
f1= open("t1file.txt",'w')
read1 = f.readlines()
for line in read1:
if line[0].upper()=="T":
f1.writelines(line)
print("content copied successfully")
copylines()
2. CSV file:
import csv
stu = []
def write_csvdata():
with open("inputdata.csv",'w',newline='')as f:
write = csv.writer(f)
ch = 'y'
while ch.lower()=='y':
name = input("Enter the students name:")
totalmarks = int(input("Enter the total marks:"))
stu =[name,totalmarks]
write.writerow(stu)
ch = input("Do you want to continue? Y / N:")
def read_csvdata():
with open("inputdata.csv",'r') as f1:
read = csv.reader(f1)
for data in read:
print(data)
write_csvdata()
read_csvdata()
3. Stack operations:
def push():
e = int(input("Enter the element to be pushed:"))
stk.append(e)
def pop():
if stk==[]:
print("Stack is empty!")
else:
print("Deleted element is",stk.pop())
def peek():
pk = len(stk)-1
print("The topmost element in the stack is:")
print(stk[pk])
def display():
print("The elements in the stack are:")
for i in range(len(stk)-1,-1,-1):
print(stk[i])
stk = []
ch = 'y'
print("Stack operations")
print("*"*16)
print("Stack operations")
print("1.Push")
print("2.Pop")
print("3.Peek")
print("4.Display")
print("*"*16)
while ch.lower()=='y':
fun = int(input("Enter your choice:"))
if fun==1:
push()
elif fun==2:
pop()
elif fun==3:
peek()
elif fun==4:
display()
else:
print("Invalid input")
ch = input("Do you want to continue? Y/N:")
set-1 SQL:
a. Write a query to change the FARE as 6000 of the flights where FNO is 104
+------+------------+--------+------------+------+
+------+------------+--------+------------+------+
+------+------------+--------+------------+------+
b. Write a query to display the total number of male and female passengers
separately.
select gender, count(*) as "total male and female passengers" from
passenger group by gender;
+--------+----------------------------------+
| gender | total male and female passengers |
+--------+----------------------------------+
|M | 3|
|F | 1|
+--------+----------------------------------+
c. Write a query to display the maximum and minimum fare from table flight.
select max(fare),min(fare) from flight;
+-----------+-----------+
| max(fare) | min(fare) |
+-----------+-----------+
| 6000 | 4500 |
+-----------+-----------+
d. Write a query to display the NAME, FDATE of the passengers whose
destination is DELHI.
mysql> select name, fdate from passenger p,flight f where p.fno = f.fno
and end = "Delhi";
+-------+------------+
| name | fdate |
+-------+------------+
| ANIKA | 2022-05-04 |
+-------+------------+
set-2 SQL:
a. To display CNAME, AREA of all female customers from CUSTOMER
table.
mysql> select cname, area from customer where gender = "female";
+-----------+-------+
| cname | area |
+-----------+-------+
| RSHARMA | NORTH |
| SSEN | WEST |
| M AGARWAL | NORTH |
| SDAS | SOUTH |
+-----------+-------+
b. To display the details of all the CUSTOMERS in ascending order of CNAME.
mysql> select * from customer order by cname;
+------+-----------+--------+------+-------+
| cid | cname | gender | sid | area |
+------+-----------+--------+------+-------+
| 1004 | AKSINGH | MALE | 102 | EAST |
| 1007 | M AGARWAL | FEMALE | 104 | NORTH |
| 1003 | MK KHAN | MALE | 103 | EAST |
| 1002 | MRTIWARY | MALE | 102 | SOUTH |
| 1006 | RDUBEY | MALE | 104 | NORTH |
| 1001 | RSHARMA | FEMALE | 101 | NORTH |
| 1008 | SDAS | FEMALE | 103 | SOUTH |
| 1005 | SSEN | FEMALE | 101 | WEST |
+------+-----------+--------+------+-------+
c. To display the total number of customers for each AREA from CUSTOMER
table.
select area, count(*) as "Total Customer" from customer group by area;
+-------+----------------+
| area | Total Customer |
+-------+----------------+
| NORTH | 3|
| SOUTH | 2|
| EAST | 2|
| WEST | 1|
+-------+----------------+
d. To display CNAME and corresponding SHOP from CUSTOMER table and
ONLINESHOP table.
select cname, shop from customer c, onlineshop o where c.sid = o.sid;
+-----------+---------------+
| cname | shop |
+-----------+---------------+
| RSHARMA | MY BUY |
| MRTIWARY | ECOBUY |
| MK KHAN | JUST SHOPPING |
| AKSINGH | ECOBUY |
| SSEN | MY BUY |
| RDUBEY | SHOPPINGEASY |
| M AGARWAL | SHOPPINGEASY |
| SDAS | JUST SHOPPING |
+-----------+---------------+
set-3 SQL:
a. Display book name, author name and price of computer type books.
+----------+----------+-------+
+----------+----------+-------+
b. To increase the price of all history books by Rs 50. (Display the content
of the table after updating the records)
update books set price = price + 50 where type = "history";
mysql> select * from books;
+--------+-----------+----------+-------+-----------+------+
| bid | bname | auname | price | type | qty |
+--------+-----------+----------+-------+-----------+------+
| COMP11 | LETUSC | YASHWANT | 350 | COMPUTER | 15 |
| GEOG33 | INDIAMAP | RANJEETP | 150 | GEOGRAPHY | 20 |
| HIST66 | HISTORY | RBALA | 260 | HISTORY | 25 |
| COMP12 | MYFIRSTC | VINODDUA | 330 | COMPUTER | 18 |
| LITR88 | MY DREAMS | ARVINDAD | 470 | NOBEL | 24 |
+--------+-----------+----------+-------+-----------+------+
c. Show the details of all the books in ascending order of their prices.
mysql> select * from books order by price;
+--------+-----------+----------+-------+-----------+------+
| bid | bname | auname | price | type | qty |
+--------+-----------+----------+-------+-----------+------+
| GEOG33 | INDIAMAP | RANJEETP | 150 | GEOGRAPHY | 20 |
| HIST66 | HISTORY | RBALA | 260 | HISTORY | 25 |
| COMP12 | MYFIRSTC | VINODDUA | 330 | COMPUTER | 18 |
| COMP11 | LETUSC | YASHWANT | 350 | COMPUTER | 15 |
| LITR88 | MY DREAMS | ARVINDAD | 470 | NOBEL | 24 |
+--------+-----------+----------+-------+-----------+------+
d. To display book id, book name and quantity issued for all books which
have been issued.
mysql> select b.bid,b.bname,i.qty_issued from books b,issued i where
b.bid = i.bid;
+--------+-----------+------------+
| bid | bname | qty_issued |
+--------+-----------+------------+
| COMP11 | LETUSC | 5|
| HIST66 | HISTORY | 10 |
| LITR88 | MY DREAMS | 15 |
+--------+-----------+------------+