0% found this document useful (0 votes)
54 views1 page

Password Prg9A

The document outlines a Python program that creates a CSV file to store user IDs and passwords. It includes functions to create the CSV file, add user information, and a main loop for continuous user input until the user decides to quit. The program utilizes the CSV module for file handling and prompts the user for input.

Uploaded by

kkanishk334
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views1 page

Password Prg9A

The document outlines a Python program that creates a CSV file to store user IDs and passwords. It includes functions to create the CSV file, add user information, and a main loop for continuous user input until the user decides to quit. The program utilizes the CSV module for file handling and prompts the user for input.

Uploaded by

kkanishk334
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

# Program No.

9 (A): Create CSV file and store user IDs and passwords
print("**** \u262C S T O R E U S E R IDs A N D P A S S W O R D S \u262C
****")
import csv

def create_csv(filename):
# Create and open the CSV file for writing
with open(filename, mode='w', newline='') as file:
writer = csv.writer(file)
# Write the header
writer.writerow(["user_id", "password"])
print()
print("\u263A *** CSV file created successfully. *** \u263A")

def add_user(filename):
print()
user_id = input("Enter user ID: ")
print()
password = input("Enter password: ")

# Open the CSV file for appending


with open(filename, mode='a', newline='') as file:
writer = csv.writer(file)
# Write the user ID and password
writer.writerow([user_id, password])
print()
print(f"User {user_id} added successfully.")

def main():
filename = "dvsusers.csv"
create_csv(filename)

while True:
add_user(filename)
print()
another = input("Press enter to add another user or 'Q' to quit: ").upper()
if another == 'Q':
print("Exiting... ")
break

if __name__ == "__main__":
main()

You might also like