day02作业

# 一练习题
# 1.简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释型
1.1 编译型(需要编译器,相当于用谷歌翻译,执行速度快,调试麻烦):如 C
1.2 解释型(需要解释器,相当于同声传译,执行速度慢,调试方便):如 python

# 2.执行 Python 脚本的两种方式是什么
交互式和脚本式

# 3.Pyhton 单行注释和多行注释分别用什么?
单行注释:#内容 多行注释:'''内容''' 或 """内容"""

# 4.布尔值分别有什么?
True 和 False

# 5.声明变量注意事项有那些?
5.1 可以是字母、数字、下划线的任意组合
5.2 不能以关键字命名
5.3 不要以下划线开头

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

# 7.写代码
# 7.1实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败!
username = input('请输入你的用户:')
password = input('请输入你的密码:')
if username == 'seven' and password == '123':
    print('登陆成功!')
else:
    print('登陆失败!')




# 7.2实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
count = 0
while count < 3:
    username = input('请输入你的用户:')
    password = input('请输入你的密码:')
    if username == 'seven' and password == '123':
        print('登陆成功!')
        break
    else:
        print('登陆失败!')
        count += 1


# 7.3实现用户输入用户名和密码,当用户名为 seven 或 alex 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
# 7.3.1用列表存多个值的方式:
l = ['seven','alex']
count = 0
while count < 3:
    username = input('请输入你的用户:')
    password = input('请输入你的密码:')
    if username in l and password == '123':
        print('登陆成功!')
        break
    else:
        print('登陆失败!')
        count += 1


# 7.3.2用字典存多个值的方式:
dict = {'name':['seven','alex']}
count = 0
while count < 3:
    username = input('请输入你的用户:')
    password = input('请输入你的密码:')
    if username in dict['name'] and password == '123':
        print('登陆成功!')
        break
    else:
        print('登陆失败!')
        count += 1




# 8.写代码
# 8.1使用while循环实现输出2-3+4-5+6...+100 的和
x = 1
y = 0
while x <= 100:
    if y % 2 == 0:
        x -= y
    else:
        x += y
    y += 1
print(x)


# 8.2使用 while 循环实现输出 1,2,3,4,5, 7,8,9, 11,12
count = 1
while count < 13:
    if count == 6 or count == 10:
        count += 1
        continue
    print(count)
    count += 1


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


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


# 9现有如下两个变量,请简述 n1 和 n2 是什么关系?
# n1 = 123456
# n2 = n1
答:赋值(链式)

# 二.作业:编写登陆接口
# 1.基础需求:让用户输入用户名和密码,认证成功后显示欢迎信息,输错三次后退出程序
count = 0
while count < 3:
    username = input('请输入你的用户:')
    password = input('请输入你的密码:')
    if username == 'Tom' and password == '123':
        print('恭喜认证成功!')
        break
    else:
        print('认证失败!')
        count += 1
原文地址:https://www.cnblogs.com/2722127842qq-123/p/13292673.html