day 06 练习题

1、编写认证程序,可以登陆成功不同的账号密码,账号密码输错3次则退出
list = [['egon', '123'], ['tank', '123'], ['alex', '123']]

count = 0
while count < 3:
    inp_name = input('Username:')
    inp_pwd = input('Password:')
    for x, y in list:
        if inp_name == x and inp_pwd == y:
                print('success')
                count = 4
                break
    else:
        print('error')
        count += 1
2、简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释型
编译型(go语言,java)翻译一次后得到结果,程序运行时不需要在翻译
解释型(python)每次执行程序都离不开解释器
3、执行 Python 脚本的两种方式是什么
交互式 和 脚本的方式
4、Pyhton 单行注释和多行注释分别用什么?
单行注释:# 多号注释:""""""、''''''
5、布尔值分别有什么?
True和False
5、声明变量注意事项有那些?
先定义,后引用
6、如何查看变量在内存中的地址?
print(id(变量名))
7、写代码
7.1、实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败!
实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
实现用户输入用户名和密码,当用户名为 seven 或 alex 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
# 1)
username = 'seven'
password = '123'
inp_name = input('Username:')
inp_pwd = input('Password:')
if username == inp_name and password == inp_pwd:
    print('success')
else:
    print('failed')

# 2)
username = 'seven'
password = '123'
count = 0
while count < 3:
    inp_name = input('Username:')
    inp_pwd = input('Password:')
    if username == inp_name and password == inp_pwd:
        print('success')
        break
    else:
        print('failed')
        count += 1

# 3)
username = ['seven','alex']
password = '123'
count = 0
while count < 3:
    inp_name = input('Username:')
    inp_pwd = input('Password:')
    if inp_name in username and password == inp_pwd:
        print('success')
        break
    else:
        print('failed')
        count += 1
8、写代码
a. 使用while循环实现输出2-3+4-5+6…+100 的和
x = 0
y = 2
while y <= 100:
    if y % 2 == 0:  # 能除2余0 的数:2,4,6,8,10...100
        x += y  # 0+2+4+6+8+10...+100
    else:  # 不能除2余0的数:3,5,7,9,11,13....99
        x -= y  # 0-3-4-7-9-11....-99
    y += 1  # 第一个y=2 ,第二个y=3,第三个y=4
print(x)
b. 使用 while 循环实现输出 1,2,3,4,5, 7,8,9, 11,12 使用 while 循环实现输出 1-100 内的所有奇数
count = 1
while count < 100:
    if count % 2 != 0:
        print(count)
    count += 1
e. 使用 while 循环实现输出 1-100 内的所有偶数
count = 1
while count < 100:
    if count % 2 == 0:
        print(count)
    count += 1

现有如下两个变量,请简述 n1 和 n2 是什么关系?

n1 = 123456
n2 = n1
n1的内存地址赋值给了n2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值