Python Forum
Trouble displaying items from lists
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble displaying items from lists
#1
So I am writing a code for an address book. I have a function that searches for a nickname of a person then prints their details if the nickname is in the list but I only getting the "contact does not exist" every time I run this Please help! also P.S does anyone have any good resources on turning lists into dictionaries? Cheers

import sys
Numbers=[]
Names=[]
nicknames=[]
address=[]


def addcontact():
        print ("-------------")
        print ("Adding a Contact\n-------------")
        name = input("Enter first and last name :").lower
        Names.append(name)
        nickname = input("Enter the nickname").lower
        nicknames.append(nickname)
        number = input("Enter number :")
        Numbers.append(number)
        Addres = input("Enter the address").lower
        address.append(Addres)
        print("***Contact added succesfully***")
        menu()

def searchcontact():
        print ("\nSearch Contact by Nickname\n--------------------")
        nick = input("Please enter the nicnkname")
        if nick in nicknames:
            print ("The Contacts are listed Below")
            print ("-----------------------------")
            index = nicknames.index(nick)
            print ("\n", nicknames[index])
            print ("\n",Names[index])
            print ("\n",address[index])
            print ("\n", Numbers[index])
        elif nick not in nicknames:
            print ("\nThis Contact Does Not Exist!!\n----------------------\n")
        menu()

def showcontact():
        for i in range(len(Names)):
            print (str(Names[i]) + "........"+ str(Numbers[i]))
        #print Names
        #print Numbers
        print ("--------------------")

def quit():
        print("Exiting....")
        sys.exit


def menu():
        print ("---------------------------------------")
        print  ("***Welcome to the Python address book***\n"+
                "\n----------------------------------------"+
                "\n| 1 | To Add Contact"+
               "\n| 2 | To search for the Contact by nickname\n| 3 | To list all contacts in the address book\n| 4 | To quit\n"+
                "----------------------------------------\n>")
menu()
while True:
        selection = input("Please Select:")
        if selection =='1':
            addcontact()
        elif selection =='2': searchcontact()
        elif selection =='3': showcontact()
        elif selection == '4': quit()
        else:
            print ("Unknown Command")
menu()
selection = input("Please Select:")
---------------------------------------
***Welcome to the Python address book***

----------------------------------------
| 1 | To Add Contact
| 2 | To search for the Contact by nickname
| 3 | To list all contacts in the address book
| 4 | To quit
----------------------------------------
>
Please Select:1
-------------
Adding a Contact
-------------
Enter first and last name :John Doe
Enter the nicknameJohnny
Enter number :123456789
Enter the address123 Hello World street
***Contact added succesfully***
---------------------------------------
***Welcome to the Python address book***

----------------------------------------
| 1 | To Add Contact
| 2 | To search for the Contact by nickname
| 3 | To list all contacts in the address book
| 4 | To quit
----------------------------------------
>
Please Select:2

Search Contact by Nickname
--------------------
Please enter the nicnknameJohnny

This Contact Does Not Exist!!
----------------------

---------------------------------------
***Welcome to the Python address book***

----------------------------------------
| 1 | To Add Contact
| 2 | To search for the Contact by nickname
| 3 | To list all contacts in the address book
| 4 | To quit
----------------------------------------
>
Please Select:
Reply


Messages In This Thread
Trouble displaying items from lists - by Liquid_Ocelot - May-17-2017, 10:42 PM
RE: Trouble displaying items from lists - by Ofnuts - May-18-2017, 06:06 AM
RE: Trouble displaying items from lists - by Ofnuts - May-18-2017, 01:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  QUERY on Looping and creating lists as items within dictionaries ajayachander 3 2,348 Mar-26-2020, 02:03 PM
Last Post: ajayachander
  Trouble in lists erfanakbari1 2 2,326 Feb-26-2019, 08:46 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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