...

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

# Python Program

 

import csv

with open("user_info.csv", "w") as obj:

    fileobj = csv.writer(obj)

    fileobj.writerow(["User Id", "password"])

    while(True):

        user_id = input("enter id: ")

        password = input("enter password: ")

        record = [user_id, password]

        fileobj.writerow(record)

        x = input("press Y/y to continue and N/n to terminate the program\n")

        if x in "Nn":

            break

        elif x in "Yy":

            continue

with open("user_info.csv", "r") as obj2:

    fileobj2 = csv.reader(obj2)

    given = input("enter the user id to be searched\n")

    for i in fileobj2:

        next(fileobj2)

        # print(i,given)

        if i[0] == given:

            print(i[1])

            break

 

 

Output:

enter id: cbse enter password: 123 press Y/y to continue and N/n to terminate the program y enter id: computer_science enter password: python press Y/y to continue and N/n to terminate the program y enter id: class12 enter password: cs083 press Y/y to continue and N/n to terminate the program n enter the user id to be searched cbse 123 >>> 

By Jitendra Singh

A complete solution for the students of class 9 to 12 having subject Information Technology (402), Computer Science (083). Explore our website for all the useful content as Topic wise notes, Solved QNA, MCQs, Projects and Quiz related to the latest syllabus.

Copywrite © 2020-2025, CBSE Python,
All Rights Reserved
error: Content is protected !!
Seraphinite AcceleratorOptimized by Seraphinite Accelerator
Turns on site high speed to be attractive for people and search engines.