Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python初学者联络簿项目_Python_Project - Fatal编程技术网

Python初学者联络簿项目

Python初学者联络簿项目,python,project,Python,Project,如何从用户处获取多个输入(不使用GUI),例如姓名、电话号码、电子邮件或ID,并将它们存储在python中的变量中。我想在用户以后搜索时向用户显示它们。我是初学者 print('Contact Book') print('''Press I to update contact Press S to scearch''') def updateContact(): Name = input('Enter Your Name: ') MobileNo = input("

如何从用户处获取多个输入(不使用GUI),例如姓名、电话号码、电子邮件或ID,并将它们存储在python中的变量中。我想在用户以后搜索时向用户显示它们。我是初学者

print('Contact Book')
print('''Press I to update contact
Press S to scearch''')


def updateContact():
    Name = input('Enter Your Name: ')
    MobileNo = input("Enter mobile: ")
    NameList = [].append(Name)


userinput = input("Press Key: ")
if userinput.upper().strip() == 'S':
    updateContact()

    

您需要的是一个
联系人
,它将包含
姓名
手机号
等属性。在
\uuuu init\uuuu
方法(类的构造函数)中,可以初始化这些属性,然后在单独的方法
showInfo
中打印它们

class Contact():
    def __init__(self):  # Constructor
        self.name = input("Enter Your Name: ")
        self.mobileNo = input("Enter mobile: ")

    def showInfo(self):  # Prints info
        print("name :", self.name, ", mobile no :", self.mobileNo)


first_contact = Contact()  # New instance of the class Contact, calls __init__()
first_contact.showInfo()  # Calls showInfo() on first_contact, which prints its attributes

非常感谢,先生…似乎在深入研究和做这样的项目之前,我不需要学习pythonobject-oriented编程…谢谢again@SultanulArefin别担心,如果你没有其他问题,请随意接受答案。接受它…愿上帝保佑你…只是一个问题,做这样的项目需要OOP吗?或者我可以用传统的方法做这种pf编程way@SultanulArefin我认为在这种情况下这是必要的,因为
name
mobileNo
是定义
联系人的属性。与使用OOP相比,将它们附加到列表或字典中会非常混乱,并且不容易使用。尤其是当您尝试创建联系人列表时,创建
联系人
对象列表比尝试在无序列表中匹配号码和姓名更具可读性。请记住,可读性是任何代码中最重要的特性。