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

















No comments:

Post a Comment