一叶扁粥

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

一、变量命名规则:

  1,要有描述性;

  2,变量名只能以  下划线,数字,字母组成,不可以有特殊符号和空格;

  3,不能以中文为变量名(规范);

  4,不能以数字开头;

  5,保留字符(即关键字:如print  if   while  等)不能作为变量名。

  1.   注:全部大写代表常量。

 

二、注释:

  单行注释:#注释

  多行注释:"""多行注释"""                (三个双引号)

       '''多行注释'''                   (三个单引号)

三、if语句格式:

if    判断语句:

  执行语句

else:

  执行语句

注:python规定缩进用4个空格。

四、作业

编写登录借口:

*输入用户名密码

*认证成功显示欢迎信息

*输错三次后锁定

my_user_name = "weiye"
my_password = "635241"
num = 0
while num < 3:
    user_name = input("please enter your username:")
    password = input("please enter your password:")

    if user_name == my_user_name and password == my_password:
        print("welcome,weiye")
        break

    else:
        num += 1
        if num != 3:
            print("input error,please enter again")
        else:
            print("username locked!")

 

posted on 2017-10-24 21:25  一叶扁粥  阅读(113)  评论(0)    收藏  举报