# Author Eric Zhao
# -*- coding:utf-8 -*-
class User():
‘‘‘
用户类
‘‘‘
def __init__(self,first_name,last_name,username,email,location):
‘‘‘
初始化属性 first_name,last_name,username,email,location
‘‘‘
self.first_name = first_name.title()
self.last_name = last_name.title()
self.username = username
self.email = email
self.location = location.title()
self.login_attempts = 0
def describe_user(self):
"""用户信息摘要"""
print("\n"+ self.first_name+"·"+self.last_name)
print("User Name is "+self.username)
print("Email is "+self.email)
print("Location is " + self.location)
def greet_user(self):
"""问候用户方法"""
print("\nHello " + self.username)
def increment_login_attempts(self):
"""企图登录增量方法"""
self.login_attempts += 1
def reset_login_attempts(self):
"""重置企图登录增量方法"""
self.login_attempts = 0
eric_user = User(‘eric‘,‘li‘,‘eric·li‘,‘556677@163.com‘,‘Beijing‘)
eric_user.describe_user()
eric_user.greet_user()
print("\nMarking 3 login attempts...")
eric_user.increment_login_attempts()
eric_user.increment_login_attempts()
eric_user.increment_login_attempts()
print(" Login attempts: "+ str(eric_user.login_attempts))
print("Resetting login attempts...")
eric_user.reset_login_attempts()
print(" Login attempts: "+ str(eric_user.login_attempts))
lisa_user = User(‘lisa‘,‘gao‘,‘lisa·gao‘,‘887766@163.com‘,‘Beijing‘)
lisa_user.describe_user()
lisa_user.greet_user()a
原文:https://www.cnblogs.com/abarcher/p/10917892.html