PW Akshay


generate functionFri, 02 Dec 2022

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

import csv def create_user(user_id): password = input('Enter a password: ') with open('users.csv', 'a') as csvfile: fieldnames = ['user_id', 'password'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writerow({'user_id': user_id, 'password': password}) def find_password(user_id): with open('users.csv', 'r') as csvfile: reader = csv.DictReader(csvfile) for row in reader: if row['user_id'] == user_id: print(row['password']) create_user('123') find_password('123')

Questions about programming?Chat with your personal AI assistant