【发布时间】:2019-10-15 17:13:28
【问题描述】:
我的程序应该存储联系人。当我输入号码时,如果没有用户输入,我需要程序继续询问号码。现在我的程序会考虑添加的联系人,即使用户输入没有输入号码。
我尝试使用 while True 或如果不是。我最接近解决问题的是程序第二次要求输入一个数字,但仅此而已。
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]:
正如我所说,如果没有用户输入,程序应该继续询问一个数字,只有当有用户输入时才进入下一步。
【问题讨论】:
标签: python if-statement user-input