Can someone review this and give it some tips? Ive awlways struggled with python programming.
# address book
# Tyler G
def search_database ():
#search algoritm
searchcriteria = raw_input("What do you want to search? ")
temp1 = open("addressbookdata","r")
for line in temp1:
if searchcriteria in line:
print ("\n")
print ("\n")
else:
print "Search yeilded zero results"
def append_to_database (info):
# append the info list to file
temp1 = open("addressbookdata","a")
temp1.write(info)
temp1.write("\n")
print ("The record was added to the database address book ")
def collect ():
# collect information...
# append_to_file ([lastname, firstname]) # etc...
lastname = raw_input("What is the persons last name? ")
firstname = raw_input("What is the persons first name? ")
phone = raw_input("What id the persons phone number? ")
email = raw_input("What is the persons email address? ")
address = raw_input("What is the persons address? ")
info = (firstname + " " + lastname + ", " + phone + ", " + email + ", " + address)
append_to_database (info)
def menu ():
answer = raw_input("Are You Creating An Entry [Press 1] \n Or Are You Searching An Entry [Press 2] ")
# ask user what to do
if answer == "1":
collect ()
if answer == "2":
search_database()
else:
print str(answer) + " is not a valid option, try again"
menu()
# start everthing:
menu ()
If they choose Use an address book:
First, ask the user for the name of the le in which their address book is stored (e.g., addresses.txt).
Import the information in that le, and save it in a dictionary; each line of the le should become
an entry in the dictionary. The key for each entry should be the contact's name. The value for
each entry should contain their address, phone number, and e-mail. (You can choose how to store
that information { the value could be a list, one long string, an object of a class you create, etc.)
Give the user options to: see an alphabetical list of every name in the address book; enter a person's
name and look up their contact info; or quit. Let them keep requesting information until they quit.
If they choose Create an address book:
Ask the user for the name of the le where the new address book should be stored.
Give the user three options: Create a single entry, Import another address book, or Quit.
To create a single entry, have them enter the relevant information one piece at a time.
To import another address book, ask them for the le name, then copy all the information in that
le to the new address book.
Allow the user to continue creating individual entries or importing other address books, writing all
the contact info to the le they named, until they choose to quit.
Throughout the program, attempt to make sure that the program will never crash fo