Question: Need help with Python program I have the following program which is meant to build a user dataframe from user input and remember the data

Need help with Python program

I have the following program which is meant to build a user dataframe from user input and remember the data each time the program is run. It's working fine with remembering the usernames, but I have 2 main issues:

1. I want users to also be able to include a password and Password to be another column name in the Dataframe. I cannot figure out how to accomplish this.

Users can have matching passwords but NOT duplicate usernames.

2. I'm opening the file in r+ mode, but this requires the "userf" file to be already existing. I want this file to instead be automatically created. I already tried r+x but this gave me an error that only 1 mode can be used

Here is my code:

import pandas as pd

usernames = []

def myFunc(): with open("userf", "r+") as f: for line in f: usernames.append(line.strip())

while True: username = input("add a username to the usernames: ").lower().strip() if username not in usernames: usernames.append(username) f.write(username + " ") else: print("username already exists, try again") continue while True: ans = input("Add another user? Y/N ").lower().strip() if ans not in ['yes', 'y', 'no', 'n']: print("Please answer y ") else: break if ans == "yes" or ans == "y": continue else: break

user_dictionary = { "Username":usernames }

mydb = pd.DataFrame(user_dictionary) print(mydb) mydb.to_json("database.json")

try: with open("database.json") as saveddb: database = pd.read_json(saveddb) except FileNotFoundError: myFunc() else: print(database) myFunc()

Need help with Python program I have the following program which is

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!