i am trying to create a simple database with inputs of friends name and age but the lasts variable its not defined apparently
Code:
import pickle
class aFriend:
def __init__(self, name , age):
self.name = name
self.age = age
self.namePlusAge = []
def addFriend(self, friend, age):
self.namePlusAge = age
def deleteFriend(self, friend, age):
self.namePlusAge.pop(friend,None)
def addingToDatabase(name):
database = open("ListOfFriends.txt")
pickle.dump(name, database, "wb")
database.close()
def readNameDataBase():
read = open("ListOfFriends.txt","rb")
readData = pickle.load(read)
for key in newFriend.namePlusAge.keys():
print(key)
read.close()
def readAgeDatabase():
read = open("ListOfFriends.txt", "rb")
readData = pickle.load(read)
for key in newFriend.namePlusAge.keys():
print(key)
read.close()
def produceMenu():
print("""
1 - Add Friend
2 - Delete a Friend
3 - List All Friends names
4 - List All Friend Ages
5 - Quit
""")
def validateMenu():
choice = int(input("Select an option"))
if choice == 1:
newFriend.addFriend(str(input("what is the friends name?")), input("What is your frriends age?"))
addingToDatabase(newFriend.namePlusAge)
produceMenu()
validateMenu()
elif choice == 2:
newFriend.deleteFriend(str(input("What is the friends name you wish to delete?"), input("What is the friends age you wish to delete")))
addingToDatabase(newFriend.namePlusAge)
produceMenu()
validateMenu()
elif choice == 3:
readNameDataBase()
produceMenu()
validateMenu()
elif choice == 4:
readAgeDataBase()
produceMenu()
ValidateMenu()
elif coice == 5:
quit()
else:
produceMenu()
validateMenu()
produceMenu()
validateMenu()
newFriend = aFriend(str(input("Input Your Name: ")), (input("Input Your Age: ")))
Comment