Program 8
Aim:
To write a python program to create a CSV file by entering user-id and password , read and
search the password for given userid.
Algorithm:
1. Start
2. Create a csv file
3. Create a write () and write the user id and password.
4. Save the user-id and password in csv file by using writer method.
5. Read the csv file by using the read() .
6. Open the file in read mode and read the file by using the reader method.
7. Create a search() and search the password for the given user-id.
8. Print the password.
9. Stop.
Program:
import csv
def write():
print("Writing data into csv file:")
f=open("D:\\data\\[Link]","w",newline='')
swriter=[Link](f)
[Link](['userid','password'])
while True:
userid=input("Enter User ID:")
password=input("Enter your password:")
data=[userid,password]
[Link](data)
ch=input("Do you want to more records :(y/n)?")
if ch in "nN":
break
print("Data write in csv file successfully")
[Link]()
def read():
f=open("D:\\data\\[Link]","r")
print("Searching data from csv file")
print("____________")
sreader=[Link](f)
for i in sreader:
print(i)
def search():
while True:
f=open("D:\\data\\[Link]","r")
print("searching data from the file")
sreader=[Link](f)
s=input("Enter Userid to search:")
found=0
for i in sreader:
if(i[0]==s):
found=1
print(i[1])
break
if(found==0):
print("sorry no record found")
ch=input("Do yo wnat to search any more records:(y/n)")
if ch in "nN":
break
[Link]()
write()
read()
search()
Result:
Thus the above python program to create a CSV file by entering user-id and password , read and
search the password for given user-id was executed successfully and the output is verified.