首页 > 其他 > 详细

编写类-用户类

时间:2019-05-24 14:24:19      阅读:104      评论:0      收藏:0      [点我收藏+]
# 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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!