SyntaxError如何修复?

2024-09-30 02:35:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我的python代码出错: 我想用python创建一个联系人管理器应用程序,用于添加一个联系人,该联系人指定了姓名、姓氏、wtsp、face(如果它确实存在的话)。。。 或编辑另一个(联系人) 或者只是删除它 需要你的帮助 这是我的密码

<



contact_list =[]

class Contact:

    nb_contact = 0

    def __init__(self ,nom ='' ,prenom='' , email ='' , tel ='' , whatsapp = '' ):

        self.nom=nom

        self.prenom= prenom

        self.email=email

        self.tel = tel

        self.whatsapp= whatsapp


        Contact.nb_contact +=1
        self.nb=Contact.nb_contact
        self=[self.nom,self.prenom,self.email,self.tel,self.whatsapp]

    def show(self):

        ch = str(self.nb)

        print("Contact :" +ch +"\n Nom  : "+self.nom +"\n Prenom  : "+self.prenom +"\n Email  : "+self.email +"\n Tel  : "+self.tel +"\n Whatsapp : "+self.whatsapp)

    def Add(self):
        contact_list.append(self)
    def Supprimer(self):
        contact_list.remove(self)

    def find_contact(self,tel):

        for l in contact_list:
            for i in l:
             n, p, e, phone, whp = l[i]
             if phone == tel:
                Contact.show(l)

    def my_contacts(self):
        print("List of my contacts :")
        for i in contact_list:

            Contact.show(i)
    def set_contact(self):
        self.nom=input("Entre  le nouveau nom :")
        self.prenom = input("Entre  le nouveau prenom :")
        self.email = input("Entre  le nouveau mail :")
        self.whatsapp = input("Entre  le nouveau whatsapp :")
        self.tel = input("Entre  le nouveau tel :")


C=Contact('eric','jean','sid@h.c','0011','144')
C1=Contact('erric','michel','sid@h.c','1111','1111')


C.Add()
C1.Add()
C1.find_contact('1111')
>

enter image description here


Tags: selfleinputemaildefcontactnomlist
1条回答
网友
1楼 · 发布于 2024-09-30 02:35:28

find_contact(tel)是一个实例方法,因此应该声明为:

def find_contact(self, tel):
    ...

当您使用以下命令调用它时:

C1.find_contact('1111')

因为它是在类的实例上调用的,所以它被转换为:

find_contact(c1, '1111')

这就是为什么你会看到一个错误,说这个方法应该只用一个参数来调用,但是给出了两个参数。你知道吗

相关问题 更多 >

    热门问题