像这样创建的,因此我有我的功能:功能是不是要我的字典里添加信息
def create_contact(contacts, first, last, email, age, phone):
"""
Creates a contact.
"""
contacts[(first, last)] = [email, age, phone]
def contains_contact(contacts, first, last):
"""
Checks to see if the dictionary contains a contact.
"""
if (first.lower(), last.lower()) in contacts == True:
return(True)
else:
return(False)
,然后在我的代码的底部,我有我的主要功能如下所示:
def main():
# The Dictionary
contacts = {}
# Provided Test Code
create_contact(contacts, "Katie", "Katz", "[email protected]",
25, "857-294-2758")
#Checks to see if item in dictionary exists
print("Creation of Katie Katz: {}".format(
"Passed" if contains_contact(contacts, "Katie", "kaTz") else
"Failed"))
我不确定我要去哪里错。似乎这些项目没有被添加到我的字典中。不确定为什么,也许我试图这一切都错了。
你不降低情况下,在关键的元组的名称。您可以'打印(联系人)'来查看功能*是*添加信息。另外你的第二个方法应该是'在联系人中返回(first.lower(),last.lower())。 – jonrsharpe
在create_contact中返回缺少 –
@DineshPundkar它改变它的参数,返回一些东西,在Python中并不常见。 – jonrsharpe