Monday, 13 January 2025

Create a CSV file by entering user-id and password, read and search the password for given user-id.

 #Program

import csv
def write():
    f=open("details.csv","w",newline='')
    wo=csv.writer(f)
    wo.writerow(["UserId","Password"])
    while True:
        u_id=input("Enter User-Id : ")
        pswd=input("Enter Password:")
        data=[u_id,pswd]
        wo.writerow(data)
        ch=input("Do you want to enter more records (Y/N) :")
        if ch in 'Nn':
            break

    f.close()

def read():
    f=open("details.csv","r")
    ro=csv.reader(f)
    for i in ro:
        print(i)
    f.close()
    
def search():
    f=open("details.csv","r")
    Found=0
    u=input("Enter user - id to search :")
    ro=csv.reader(f)
    next(ro)
    for i in ro:
        if i[0]==u:
            print(i[1])
            Found=1

    f.close()
    if Found==0:
        print("Sorry.....No record Found..")
    
    
write()
read()
search()


Output

















Tuesday, 10 September 2024

SQL-2



 Consider the tables Admin and Transport given below:

Table: ADMIN

Table: TRANSPORT







CREATE TABLE ADMIN(S_ID VARCHAR(5) PRIMARY KEY,S_NAME VARCHAR(10), ADDRESS VARCHAR(10), S_TYPE VARCHAR(15));






DESC ADMIN;








INSERT INTO ADMIN(S_ID,S_NAME,ADDRESS,S_TYPE)VALUES ('S001','SANDYA','ROHINI','DAY BOARDER');

INSERT INTO ADMIN(S_ID,S_NAME,ADDRESS,S_TYPE)VALUES('S002','VEDANSHI','ROTHAK','DAY SCHOLAR');

INSERT INTO ADMIN(S_ID,S_NAME,ADDRESS,S_TYPE)VALUES('S003','VIBHU','RAJ NAGAR','NULL');

INSERT INTO ADMIN(S_ID,S_NAME,ADDRESS,S_TYPE)VALUES('S004','ATHARVA','RAMPUR','DAY BOARDER');

SELECT * FROM ADMIN;







CREATE TABLE TRANSPORT(S_ID VARCHAR(5) PRIMARY KEY, BUS_NO VARCHAR(6), STOP_NAME VARCHAR(17));

DESC TRANSPORT;






INSERT INTO TRANSPORT(S_ID,BUS_NO,STOP_NAME)VALUES('S002','TSS10','SARAI KALE KHAN');

INSERT INTO TRANSPORT(S_ID,BUS_NO,STOP_NAME)VALUES('S004','TSS12','SAINIK VIHAR');

INSERT INTO TRANSPORT(S_ID,BUS_NO,STOP_NAME)VALUES('S005','TSS10','KAMLA NAGAR');

SELECT * FROM TRANSPORT;







Write SQL queries for the following:

(i)  Display the student name and their stop name from the table Admin and Transport.

Ans.   SELECT S_NAME,STOP_NAME FROM ADMIN,TRANSPORT WHERE ADMIN.S_ID=TRANSPORT.S_ID;






(ii) Display the number of students whose S_TYPE is not known.

Ans. SELECT COUNT(*) FROM ADMIN WHERE S_TYPE IS NULL;







(iii) Display all details of the students whose name starts with 'v',

Ans. SELECT * FROM ADMIN WHERE S_NAME LIKE 'V%';








(iv) Display student id and address in alphabetical order of student name, from the table Admin.

Ans. SELECT S_ID, ADDRESS FROM ADMIN ORDER BY S_NAME;







SQL-1

 create database CSIP;

us CSIP;

consider the table ORDERS given below and write the output of the SQL queries that follow


CREATE TABLE ORDERS(ORDNO INTEGER PRIMARY KEY, ITEM VARCHAR(12),QTY INTEGER, RATE INTEGER, ORDATE DATE);





DESC ORDERS;\






INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1001,'RICE',23,120,'2023-09-10');

INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1002,'PULSES',13,120,'2023-10-18');

INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1003,'RICE',25,110,'2023-11-17');

INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1004,'WHEAT',28,120,'2023-12-25');

INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1005,'PULSES',16,110,'2024-01-15');

INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1006,'WHEAT',27,55,'2024-04-15');

INSERT INTO ORDERS(ORDNO,ITEM,QTY,RATE,ORDATE) VALUES(1007,'WHEAT',25,60,'2024-04-30');


SELECT * FROM ORDERS;


(i) SELECT ITEM, SUM(QTY) FROM ORDERS GROUP BY ITEM;

Ans.


(ii) SELECT ITEM, QTY FROM ORDERS WHERE  ORDATE BETWEEN '2023-11-01' AND '2023-12-31';

Ans.






(iii) SELECT  ORDNO, ORDATE FROM ORDERS WHERE ITEM = 'WHEAT' AND RATE >=60;
Ans.