Question

Lab 3: Databased Admin Tool Python Objective: Develop an admin tool for username and password management....

Lab 3: Databased Admin Tool Python

Objective: Develop an admin tool for username and password management. You will need to use the best data structure to store the data you read from UD.txt for efficient processing. You can accomplish these tasks with Dictionary or List.

The data file (UD.txt) :

FIRST NAME, LAST NAME,USERNAME,PASSWORD

Sam, DDal,sdd233,Pad231

Dave,Dcon,dcf987, BHYW4fw

Dell,Grant,dgr803,Sb83d2d

Mike,Kress,mkr212,UNNHS322

Lisa,Kate,lki065,dgw6234

Paul,Edward,ped332,9891ds

Youyou,Tranten,ytr876,dsid21kk

Nomi,Mhanken,nmh223,3282jd3d2

Write a program that imports the database from UD.txt

Give the following options:

A: Search by last name

B: Search by first name

C: Search by username

D: Display all users alphabetically by First name

E. Display all users alphabetically by Last name

F: Insert a user

  1. When user select A, prompt the user “Enter user’s last name:”

If the user is found, display the user’s info. For example: Sam, DDal,sdd233,Pad231

If user not found, display “Not found”, and return the user to main menu

  1. When user select B, prompt the user “Enter user’s first name:”

If the user is found, display the user’s info. For example: Sam, DDal,sdd233,Pad231

If user not found, display “Not found”, and return the user to main menu

  1. When user select C, prompt the user “Enter user’s username:”

If the user is found, display the user’s info. For example: Sam, DDal,sdd233,Pad231

If user not found, display “Not found”, and return the user to main menu

  1. For D, display all the user’s information with First name in alphabetically order. For example, with our current database, “Dave, Dcon,dcf987, BHYW4fw” will appear first, and “Youyou,Tranten,ytr876,dsid21kk” will appear last.
  2. For E, display all the user’s information with Last name in alphabetically order. For example, with our current database, “Dave, Dcon,dcf987, BHYW4fw” will appear first, and “Youyou,Tranten,ytr876,dsid21kk” will appear last.
  3. For F, prompt the user “Enter user info in the following format: First name, last name, username, password”, process the string and save the information into the UD.txt.

Important: Declare one function called “def output ()” to output information for option D and E.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

source code:

#Please go through comments and modify if any thing required thank you

#screenshots provided for indentation and reference purposes


#output function for D and E options
#prints the list if provided
def output(data):
print('{0: <20}{1: <20}{2: <20}{3: <20}'.format("FIRST NAME","LAST NAME","USERNAME","PASSWORD"))
for ml in data:
print('{0: <20}{1: <20}{2: <20}{3: <20}'.format(ml[0],ml[1],ml[2],ml[3]))
  
#main function
def main():
file=open("UD.txt","r") #text file opening
ml=list()
i=0
for line in file: #reading line by line and listing all contents as each list
if i!=0:
ll=line.split(",")
ml.append(ll)
i=1
file.close() #closed text file
print("Select from following options:\n") #user given with options
print("A: Search by last name\nB: Search by first name\nC: Search by username\nD: Display all users alphabetically by First name\nE. Display all users alphabetically by Last name\nF: Insert a user\n")
ch=input("Q for quit.")
while(True):
if ch=='Q':#quits
break;
elif ch=='A':#searches content using last name
name=input("Enter last name to Search: ")
i=0
j=0
for ll in ml:
if ll[1]==name:
i=j
break;
j=j+1
if i==0:
print("Not Found")
else:
print('{0: <20}{1: <20}{2: <20}{3: <20}'.format(ml[i][0],ml[i][1],ml[i][2],ml[i][3]))
elif ch=='B':#searches name using first name
name=input("Enter first name to Search: ")
i=0
j=0
for ll in ml:
if ll[0]==name:
i=j
break;
j=j+1
if i==0:
print("Not Found")
else:
print('{0: <20}{1: <20}{2: <20}{3: <20}'.format(ml[i][0],ml[i][1],ml[i][2],ml[i][3]))
elif ch=='C':#searches using usrname
name=input("Enter username to Search: ")
i=0
j=0
for ll in ml:
if ll[2]==name:
i=j
break;
j=j+1
if i==0:
print("Not Found")
else:
print('{0: <20}{1: <20}{2: <20}{3: <20}'.format(ml[i][0],ml[i][1],ml[i][2],ml[i][3]))
elif ch=='D':#sorts the data using first name
rl=ml
rl.sort(key=lambda x:x[0])
output(rl)
elif ch=='E':#sorts data using last name
rl=ml
rl.sort(key=lambda x:x[1])
output(rl)
elif ch=='F':#writest to text file
det=input("Enter user info in the following format: First name, last name, username, password:")
file=open("UD.txt","a")
file.write("\n")
file.write(det)
file.close
print("Select from following options:\n")
print("A: Search by last name\nB: Search by first name\nC: Search by username\nD: Display all users alphabetically by First name\nE. Display all users alphabetically by Last name\nF: Insert a user\n")
ch=input("Q for quit.")


if __name__ == '__main__':
main()

Add a comment
Know the answer?
Add Answer to:
Lab 3: Databased Admin Tool Python Objective: Develop an admin tool for username and password management....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT