zoukankan      html  css  js  c++  java
  • Python入门——练习

    # _*_coding:utf-8_*_
    # 1.简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释型
    # 编译型:需要编译器,执行速度快,调试麻烦,跨平台差
    # e.g. CC++

    # 解释型:不需要编译器,执行一行翻译一行,执行速度慢,调试方便
    # 跨平台性好,依赖解释器运行
    # e.g. PythonJava

    # 2.执行 Python 脚本的两种方式是什么
    # 交互式环境:输入代码立即执行,得到结果
    # 命令行:python3 test.txt 以文件的方式将代码永久保存

    # 3.Pyhton 单行注释和多行注释分别用什么?
    # 单行注释用#
    # 多行注释用 ''' …………
    # …………
    # '''

    # 4.布尔值分别有什么?
    # True False bool值在判断中用

    # 5.声明变量注意事项有那些?
    # 1.变量的命名应该能够反应出值的状态
    # 2.变量名只能是字母、数字、下划线
    # 3.变量名的第一个字符不能是数字
    # 4.不能是PYTHON的关键字

    # 6.如何查看变量在内存中的地址?
    # print(id(a))

    # 7.写代码
    # 1.实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败!
    # username = 'seven'
    # pwd = '123'
    # name = input('Please enter your username:')
    # password = input('Please enter your password:')
    # if name == username and password == pwd:
    # print("login successful!")
    # else:
    # print("login failed!")

    # 2.实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
    # username = 'seven'
    # pwd = '123'
    #
    # count = 1
    # while count < 4:
    # name = input('Please enter your username:')
    # password = input('Please enter your password')
    # if name == username and pwd == password:
    # print('login successful')
    # break
    # else:
    # print('login failed')
    # count += 1

    # 3.实现用户输入用户名和密码,当用户名为 seven 或 alex 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
    # username = 'seven'
    # username1 = 'alex'
    # pwd = '123'
    #
    # count = 1
    # while count < 4:
    # name = input('Please enter your username:')
    # password = input('Please enter your password')
    # if (name == username) or (name == username1) and pwd == password:
    # print('login successful')
    # break
    # else:
    # print('login failed')
    # count += 1
    # 8.写代码
    # a. 使用while循环实现输出2-3+4-5+6...+100 的和
    # tag = 1
    # count = 2
    # sum = 0
    # while count<=100:
    #
    # sum = sum + tag * count
    # tag *= -1
    # count += 1
    #
    # print(sum)

    # b. 使用 while 循环实现输出 1,2,3,4,5,7,8,9,11,12
    # count = 0
    # while count<=11:
    # count +=1
    # if count == 6 or count == 10:
    # continue
    # print(count)
    # c.使用 while 循环实现输出 1-100 内的所有奇数
    # count = 0
    # while count <=99:
    # count +=1
    # if count%2 ==1:
    # print(count)

    # d. 使用 while 循环实现输出 1-100 内的所有偶数
    # count = 0
    # while count <= 99:
    # count += 1
    # if count % 2 == 0:
    # print(count)

    # 9.现有如下两个变量,请简述 n1 和 n2 是什么关系?
    # n1 = 123456
    # n2 = n1
    # print(id(n1),id(n2))
    # id地址相同 计算值绑定两个变量名

    # 作业:编写登陆接口
    # 基础需求:
    # 让用户输入用户名密码
    # 认证成功后显示欢迎信息
    # 输错三次后退出程序

    # user_info = {
    # 'oOC':{'password':'123','count':0},
    # 'Egon':{'password':'123','count':0},
    # 'David':{'password':'123','count':0},
    # }
    # while True:
    # name = input('username>>: ')
    #
    # if not name in user_info:
    # print('用户不存在')
    # continue
    # if user_info[name]['count']>2:
    # print('尝试次数过多,锁定')
    # continue
    #
    # password = input('password>>: ')
    #
    # if password == user_info[name]['password']:
    # print('login successful')
    # break
    # else:
    # print('密码输入错误')
    # user_info[name]['count']+=1


    # 升级需求

    # dic = {
    # 'egon1': {'password': '123', 'count': 0},
    # 'egon2': {'password': '123', 'count': 0},
    # 'egon3': {'password': '123', 'count': 0},
    # }
    #
    # count = 0
    # while True:
    # name = input('u>>: ')
    # if name not in dic:
    # print('User does not exist: ')
    # continue
    #
    # with open('db.txt', 'r') as f:
    # lock_users = f.read().split('|')
    # if name in lock_users:
    # print('user %s locked' %name)
    # break
    #
    # if dic[name]['count'] > 2:
    # print('try too much times,locked')
    # with open('db.txt', 'a') as f:
    # f.write('%s|' % name)
    #
    # break
    #
    # password = input('p>> ')
    #
    # if password == dic[name]:
    # print('login successful')
    # break
    # else:
    # print('login failed')
    # dic[name]['count'] += 1
  • 相关阅读:
    Docker Registry 管理镜像
    Dockerfile 构建镜像
    制作docker镜像
    docker 使用及基本命令
    centos7 安装 docker
    spring-boot-devtools 热部署
    mysql库复制
    windows下安装和设置gradle
    springboot项目搭建
    下载和安装
  • 原文地址:https://www.cnblogs.com/OutOfControl/p/9656466.html
Copyright © 2011-2022 走看看