Python Forum
creating an 'adress book' in python using dictionaries?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creating an 'adress book' in python using dictionaries?
#2
I think you should do something like this -
adressDict = {'phony' : {'name' : 'Phony Phony', 'phone' : 'PhonyNum', 'adress' : 'Pony adress'}}

def addPerson():
    nickname = input('Type a nickname for the person\n - ')
    name = input('Type their full name\n - ')
    adress = input('Type their adress\n - ')
    phone = input('Type their phone number\n - ')
    add = False
    for i in adressDict:
        if i.lower() == name.lower():
            print('Name already there')
        elif adressDict[i]['name'].lower() == name.lower():
            print('Name already there')
        else:
            add = True
    if add:
        adressDict.update({nickname : {'name' : name, 'phone' : phone, 'adress' : adress}})

def indexPerson():
    name = input('Type the person\'s name or nickname\n - ')
    for i in adressDict:
        if i.lower() == name.lower() or adressDict[i]['name'].lower() == name.lower():
            print('\nName: %s\nPhone Number: %s\nAdress: %s\n' %(adressDict[i]['name'], adressDict[i]['phone'], adressDict[i]['adress']))
        else:
            print('Name not found')
        
def yesNo():
    yesNo = input('Would you like to add a person to the adress book y/n \n - ')
    if yesNo == 'n':
        indexPerson()
    elif yesNo == 'y':
        addPerson()
    else:
        print('Invalid response')


def main():
    while True:
        yesNo()
        Quit = input('Would you like to quit y/n \n - ')
        if Quit == 'n':
            pass
        elif Quit == 'y':
            break
        else:
            print('Invalid response')

main()
quit()
You can also use pickle to save everything to a txt document
Reply


Messages In This Thread
RE: creating an 'adress book' in python using dictionaries? - by SheeppOSU - May-04-2019, 05:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner stuck in Python book for kids mic81k 11 1,608 Nov-27-2023, 04:28 AM
Last Post: deanhystad
  Deitel book "Python for Programmers" ricardian 7 28,003 May-12-2023, 01:33 PM
Last Post: snippsat
  best " Learning Python " book for a beginner alok 4 3,216 Jul-30-2021, 11:37 AM
Last Post: metulburr
  Nested Python functions (Dan Bader's book) Drone4four 4 2,751 Jun-26-2021, 07:54 AM
Last Post: ndc85430
  I really need help, I am new to python, I am using a book that helps me to learn JaprO 5 3,262 Nov-28-2020, 02:30 PM
Last Post: JaprO
  Creating a list of dictionaries while iterating pythonnewbie138 6 3,473 Sep-27-2020, 08:23 PM
Last Post: pythonnewbie138
  listdir on IP Adress OEMS1 3 3,088 Jul-19-2020, 06:01 PM
Last Post: bowlofred
  Creating Nested Dictionaries Confusion gw1500se 2 2,259 May-18-2020, 11:16 PM
Last Post: gw1500se
  creating a list of dictionaries from API calls AndrewEnglsh101 5 3,295 Apr-03-2020, 02:21 PM
Last Post: AndrewEnglsh101
  Data Dictionaries in Python mrsenorchuck 16 7,783 Nov-25-2019, 09:29 PM
Last Post: mrsenorchuck

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020