0% found this document useful (0 votes)
54 views7 pages

Def Mainmenu

The document defines a mainmenu function that allows a user to register, update, or delete entries from a list. It uses several counters and lists to track names, addresses, and ages. The function presents a menu, gets user input, and either adds a new entry by appending to the lists and writing to a file, updates an existing entry by replacing the address or age in the lists and rewriting the file, or deletes an entry by removing it from the lists and rewriting the file with the updated data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views7 pages

Def Mainmenu

The document defines a mainmenu function that allows a user to register, update, or delete entries from a list. It uses several counters and lists to track names, addresses, and ages. The function presents a menu, gets user input, and either adds a new entry by appending to the lists and writing to a file, updates an existing entry by replacing the address or age in the lists and rewriting the file, or deletes an entry by removing it from the lists and rewriting the file with the updated data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

def mainmenu():

counter1 = 1

counter2 = 0

x=0

a=0

b=0

namelist = []

addlist = []

agelist = []

while x==0:

print("[1]Register\n[2]Update\n[3]Delete")

cho = input("Enter choice: ")

if (cho==1):
newname = raw_input("Enter Name: ")

newadd = raw_input("Enter Address: ")

newage = raw_input("Enter Age: ")

namelist.append(newname)

addlist.append(newadd)

agelist.append(newage)

f = open("assignment.txt","w")

for b in range(counter1):

f.writelines(namelist[b])

f.writelines("\n")

f.writelines(addlist[b])

f.writelines("\n")
f.writelines(agelist[b])

f.writelines("\n")

f.close()

print counter1

counter1+=1

counter2+=1

elif (cho==2):

newname = raw_input("Enter Name: ")

for a in range(counter2):

if(namelist[a]==newname):

print("[1]Address\n[2]Age")

cho = input("Enter your choice: ")

if cho==1:
desadd = raw_input("Enter new address: ")

addlist[a]=desadd

f = open("assignment.txt","w")

for b in range(counter2):

f.writelines(namelist[b])

f.writelines("\n")

f.writelines(addlist[b])

f.writelines("\n")

f.writelines(agelist[b])

f.writelines("\n")

f.close()

elif cho==2:
desage = raw_input("Enter new age: ")

agelist[a]=desage

f = open("assignment.txt","w")

for b in range(counter2):

f.writelines(namelist[b])

f.writelines("\n")

f.writelines(addlist[b])

f.writelines("\n")

f.writelines(agelist[b])

f.writelines("\n")

f.close()

elif (cho==3):

newname = raw_input("Enter Name: ")


newc1 = counter1

newc2 = counter2

for a in range(newc1-1):

if namelist[a]==newname:

del namelist[a]

del addlist[a]

del agelist[a]

f = open("assignment.txt","w")

for b in range(newc2-1):

f.writelines(namelist[b])

f.writelines("\n")

f.writelines(addlist[b])
f.writelines("\n")

f.writelines(agelist[b])

f.writelines("\n")

f.close()

counter2-=1

counter1-=1

cho = raw_input("Do you wish to try again? y/n: ")

if cho=='y':

continue

else:

break

mainmenu()

You might also like