mardi 15 octobre 2019

How to repeat the function when there is no user input

My program is supposed to store contacts. When I enter the number I need the program to keep asking for the number if there is no user input. For now my program considers the contact added even if there is no number entered by user input.

I tried to use a while True or if not. The closest I got to solving the problem was when the program asked a second time for to enter a number but that's all.

def add_contact(name_to_phone):

    # Name...
    names = input("Enter the name of a new contact:")


    # Number...
    numbers = input("Enter the new contact's phone number:")


    # Store info + confirmation
    name_to_phone[names]= numbers
    print ("New contact correctly added")

    return
Select an option [add, query, list, exit]:add
Enter the name of a new contact:Bob
Enter the new contact's phone number:
New contact correctly added
Select an option [add, query, list, exit]:

As I said the program should keep asking for a number if there is no user input and go to the next step only when there is a user input.

Aucun commentaire:

Enregistrer un commentaire