如何继续在Python中运行循环

时间:2019-08-07 23:31:55

标签: python loops

我正在尝试创建电话簿,除了我需要一遍又一遍地运行整个代码(而不是一个单独的if语句)之外,我拥有所有东西。我不确定如何继续任何建议?

我使用了while循环。

 #Intro
 print("Address book to store friends contact")
 print("-" * 50)
 print("-" * 50)

 #Display of options
 print("Select an option: ")
 print("1-Add/Update contact")
 print("2- Display all contacts")
 print("3- Search")
 print("4- Delete contact")
 print("5- Quit")

 #Selection
 option = input("Select which one you would like to choose. Ex. Select an 
 option. Type here:  ")

 #Map
 contacts = {}

 #Main program
 for i in range(0,1):
     if option == "Add/Update contact":
         person_added = input("Who would you like to be updated or added")
         next_question = input("What is there contact information")
     #The code below will add the person to the list or update them
         contacts [person_added] = next_question

     elif option == "Display all contacts":
         print(contacts)

     elif option == "Search":
         search_question = input("Who are you looking for: ")
         for search in contacts.items():
             if search == search_question:
                 print("I found" + search)
             else:
                 print("Contact not found")

     elif option == "Delete contact":
         person_deleted = input("Who would you like to be deleted ")
         del(contacts[person_deleted])

     else:
         print("Thank You! Goodbye")

0 个答案:

没有答案