# -*- conding:utf-8 -*- class User: def __init__(self,first_name,last_name,age,sex,phone,login_attempts = 0): self.first_name = first_name self.last_name = last_name self.age = age self.sex = sex self.phone = phone self.login_attempts=login_attempts def describe_user(self): print('我叫 %s %s,今年%d岁,我的电话是%s'%(self.first_name,self.last_name,self.age,self.phone)) def greet_user(self): print('尊敬的%s,您好!'%self.first_name) #递增登录次数 def increment_login_attempts(self): self.login_attempts += 1 print('%s的登录次数为:%d'%(self.first_name,self.login_attempts)) #重置登录次数 def reset_login_attempts(self): self.login_attempts = 0 print('%s的登录次数为:%d' % (self.first_name, self.login_attempts)) if __name__ == '__main__': joe = User('Joe','Black',20,'男','18011123333') #joe.describe_user() # joe.greet_user() joe.increment_login_attempts() joe.increment_login_attempts() joe.increment_login_attempts() joe.increment_login_attempts() joe.reset_login_attempts()