zoukankan      html  css  js  c++  java
  • 编写类-用户类

    # 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(" "+ 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(" Hello " + 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(" Marking 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
  • 相关阅读:
    C#编程:依赖倒置原则DIP
    java项目与javaweb项目导入jar包的区别
    《C#从入门到精通(第3版)》目录
    Sublime Text 格式化代码
    ThinkPHP 入门
    CentOS 7.2配置LAMP环境——yum版
    打包名命令:tar
    不规则数组的构建
    Linux文件权限概念
    tomcat启动成功但是没有监听8080端口
  • 原文地址:https://www.cnblogs.com/abarcher/p/10917892.html
Copyright © 2011-2022 走看看