python - 如何将函数合并到带输入的函数中?
问题描述
我正在尝试创建一个工作通讯簿,但一直在创建主页部分。在我的代码中,我尝试使用子父继承,但它不起作用。帮助?通讯簿的任何其他提示将不胜感激。谢谢!
class Parent:
def Create():
create_contact = input('''Please input the details of the contact you would like to create.
''')
addressbook.append(create_contact)
print("Successfully added")
return
def Remove_contact(remove_contact):
remove_contact = input('''Please input the details of the contact you would like to remove.
''')
if 'remove_contact' in addressbook:
print(addressbook.remove(remove_contact))
else:
print("Error, 'search_contact' not found in the list")
return remove_contact
def Search():
search_contact = input('''Please input the details of the contact you would like to search for.
''')
if 'search_contact' in addressbook:
print("'search_contact' found in Address Book")
else:
print("Error, 'search_contact' not found in the list")
return
def Display_contacts():
print("Displaying contacts....", addressbook)
return
def menu(Parent):
menu = input('''Address book to store friends contact
-------------------------------------------------------------
-------------------------------------------------------------
Select an option...
1 - Add/Update contact...
2 - Display all contacts...
3 - Search...
4 - Delete contact...
5 - Quit
''')
if menu == '1':
Create()
elif menu == '2':
Display_contacts()
elif menu == '3':
Search()
elif menu == '4':
Remove_contact(remove_contact)
elif menu == '5':
print("Quitting program")
quit()
else:
print("I did not understand that... Please try again")
menu(Parent)
解决方案
这是代码。您忘记添加函数派生的类。
addressbook = []
class Parent:
def Create():
create_contact = input('''Please input the details of the contact you would like to create.
''')
addressbook.append(create_contact)
print("Successfully added")
return
def Remove_contact(remove_contact):
remove_contact = input('''Please input the details of the contact you would like to remove.
''')
if 'remove_contact' in addressbook:
print(addressbook.remove(remove_contact))
else:
print("Error, 'search_contact' not found in the list")
return remove_contact
def Search():
search_contact = input('''Please input the details of the contact you would like to search for.
''')
if 'search_contact' in addressbook:
print("'search_contact' found in Address Book")
else:
print("Error, 'search_contact' not found in the list")
return
def Display_contacts():
print("Displaying contacts....", addressbook)
return
def menu(Parent):
menu = input('''Address book to store friends contact
-------------------------------------------------------------
-------------------------------------------------------------
Select an option...
1 - Add/Update contact...
2 - Display all contacts...
3 - Search...
4 - Delete contact...
5 - Quit
''')
if menu == '1':
Parent.Create()
elif menu == '2':
Parent.Display_contacts()
elif menu == '3':
Parent.Search()
elif menu == '4':
Parent.Remove_contact(Parent.remove_contact)
elif menu == '5':
print("Quitting program")
quit()
else:
print("I did not understand that... Please try again")
menu(Parent)
推荐阅读
- android-studio - 我们可以为 Flutter 使用 Android-Studio 翻译编辑器吗?
- excel - 嵌套 if 在 Microsoft excel 中用于部分匹配字符串的解决方案
- c++ - 求和 3 个数字的最快方法
- php - Laravel试图通过关系和查询获取非对象的属性“名称”
- python - 如何使用 beautifulsoup 从 html 中过滤掉我想要的所有“彩色”单词
- flutter - 让容器比孩子大一点?
- javascript - 如何在循环结束时返回数组(新手问题)
- spring-boot - 在 Axon Aggregate 中重放的原因
- r - 为什么 as.Date 为有效日期返回 NA?
- azure - 构建/发布管道的执行是否会创建一个新的基础文件夹,其路径包含代理编号或构建/发布编号?