zoukankan      html  css  js  c++  java
  • 路飞学城-Python开发-第一章

    # 基础需求:
    # 让用户输入用户名密码
    # 认证成功后显示欢迎信息
    # 输错三次后退出程序
    username = 'pandaboy'
    password = '123'
    def Login(username,password):
        i=0
        while i<3:
            U = input('Please input username>>>')
            P = input('Please input password>>>')
            if U == username and P == password:
                print('Welcome
    '+username)
                break
            else:
                i+=1
                if 3-i !=0:
                    print("Sorry,Don't U forget your account? Please try again,you still have	" +str(3-i) +"	times.")
                else:
                    print("Sorry! I am shutting down!")
                    break
    if __name__ == '__main__':
        Login(username,password)
    第一次作业(basic)
    # 升级需求:
    # 可以支持多个用户登录 (提示,通过列表存多个账户信息){pandaboy的疑问:用列表存储应该更好?}
    # 用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(提示:需把用户锁定的状态存到文件里)
    '''
    1.用户可以输入3次不同的账户,都输错也不会锁定
    2.用户全部输入三次相同用户名错误才会锁定
    3.创建一个初始化状态的文件
    参考了博客文件
    '''
    import os.path
    import pickle
    username= ['pandaboy','zombie','plant']
    password = ['123','456','789']
    def Login(username,password):
        i=0
        while i<3:
            if not os.path.isfile('lock_file'):
                f = open('lock_file', 'wb')
                msg = {'pandaboy': 0, 'zombie': 0, 'plant': 0}
                pickle.dump(msg, f)
                f.close()
            f = open('lock_file', 'rb+')
            msg = pickle.load(f)
            U = input('Please input username>>>')
            if U not in msg :
                print('No such	' +U+ '	account! Try again!')
                f.close()
                continue
            if msg[U] == 3:
                print('your account has been locked,please contact the administrator!')
                f.close()
                break
            P = input('Please input password>>>')
            if U  in username and P == password[username.index(U)]:
                print('Welcome', U)
                msg[U] = 0
                f.seek(0)
                pickle.dump(msg, f)
                f.close()
                break
            else:
                print('Wrong password!')
                msg[U] += 1
                print('Find %s errors' % msg[U])
                f.seek(0)
                pickle.dump(msg, f)
                f.close()
    if __name__ == '__main__':
        Login(username,password)
    第二次作业(upgrade)

    Python开发IDE(工具)
    Pycharm、eclipse
    1.循环
    while 条件
    #循环体
    #条件为真则执行
    #条件为假则执行
    break用于退出所有循环
    continue用于退出当前循环

    2.Pycharm的run
    本质上是自动调用python使用的解释器

    3.Python基本运算符
    + - * / ** %

    4.Python字符串
    #"一二三" 在Python种包含的是三个字符
    name ="自动导入模板新"
    if "自动" in name:
    print("包含")
    else:
    print("不包含")
    #in表示是否包含子字符串(连续的叫做子序列、子字符串),判断连续的字符在不在选择的字符串中
    #in或者not in判断某个字符是否在某个字符中

    5.布尔值(真假值)
    #真 True 
    #假 False
    if True :
    执行语句
    else:
    执行语句

    6.破解安装方法
    http://blog.csdn.net/doc_wei/article/details/77996223
    http://idea.lanyus.com/
    (-javaagent:C:Program FilesJetBrainsPyCharm 2017.3.3libJetbrainsCrack-2.7-release-str.jar)

    神秘学习代码:https://www.cnblogs.com/nulige/p/6128674.html

    7.简单的Python运算符
    ==
    >
    <
    >=
    <=
    !=不等于
    <>不等于

    user == 'id'and(or) pwd =='password'#执行的优先级是从左到右执行,先计算括号内的数据再把计算完成的括号内数据再进行比较计算

    8.Python的运算法则
    比较运算
    a=1>5
    逻辑运算
    a=1>6 or 1==1
    成员运算
    a="wen" in "文"

    9.Python的基本数据类型
    每一种数据的类型都具有共同的功能
    数字
    #具有类型int(Python3不管数字有多大)
    #所有的功能都包含在int里
    int()可以将字符串转换为数字['123a'这样的字符串是不能改为数字的,会出现报错]
    int(num,base=2)将字符串按照2进制的形式转换成为数字形式
    .bit_length统计数字用二进制表示时具有几位


    字符串
    #字符串表示str(字符串的用法最重要)
    #str.title()
    #str.upper()
    #str.startwith('xx')
    #v1=test.casefold()#所有的都变小写,许多未知的对相应的变为小写
    #v2=test.center(20,"^")#一共10个位置,将字符串放中间,不写则空白填充,只能写一个字符
    #



    upper()表示大写的英文字母

    列表(列表的用法次重要)
    #列表表示为list



    元祖
    #元祖表示为tuple


    字典
    #字典表示为dict



    布尔值
    #布尔值表示为bool

    Win a contest, win a challenge
  • 相关阅读:
    php
    nginx
    docker
    pyenv 配置python虚拟环境
    [运维笔记] Nginx编译安装
    [运维笔记] Mysql单库备份脚本
    BurpSuite Intruder 4种攻击模式
    java判断一个单向链表是否有环路
    二分查找(递归和非递归)
    反转链表算法题
  • 原文地址:https://www.cnblogs.com/pandaboy1123/p/9211109.html
Copyright © 2011-2022 走看看