PYTHON-DAY4-流程控制之if/while/for-作业

# 1 练习题
#
# 简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释型
# 编译型:C, 谷歌翻译,一次翻译后结果后重复使用
# 解释型:Python, 同声传译,边执行边翻译

# 执行 Python 脚本的两种方式是什么
# 1,交互式,输入命令后执行
# 2,命令行的方式,以文件的方式将代码永久保存下来

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

# 布尔值分别有什么?
# True,Fales

# 命名变量注意事项有哪些?
# 1,只能使用字母,数字和下划线
# 2,不能使用python的关键字
# 3,不能以数字开头


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

# 写代码
# 实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败!
# 实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
# 实现用户输入用户名和密码,当用户名为 seven 或 alex 且 密码为 123 时,显示登陆成功,否则登陆失败,失败时允许重复输入三次
# s_un=['seven','alex']
# s_pw='123'
# tag=True
# count=0
# while tag:
# un=input('your username>>>')
# pw=input('your password>>>')
# if un in s_un and pw == s_pw:
# print('login in')
# tag=False
# else:
# print('your username or password error')
# count+=1
# if count == 3:
# print('account blocked')
# tag = False

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

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

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

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



# 现有如下两个变量,请简述 n1 和 n2 是什么关系?
# n1 = 123456
# n2 = n1
# print(type(n1),type(n2),id(n1),id(n2),n1,n2)
# <class 'int'> <class 'int'> 5235232 5235232 123456 123456
# 变量值的ID,type,value都相同

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

# dic={
# 'aaa':{'pw':'123','count':0},
# 'bbb':{'pw':'234','count':0},
# 'ccc':{'pw':'456','count':0}
# }
# tag=True
# count=0
# while tag:
# un=input('your username>>>')
# if not un in dic:
# print('non username')
# count+=1
# if un in dic:
# pw = input('your password>>>')
# if pw == dic[un]['pw']:
# print('welcome')
# break
# else:
# print('password error')
# count+= 1
# if count > 2:
# print('account blocked')
# break

# 升级需求:
#
# 可以支持多个用户登录 (提示,通过列表存多个账户信息)
# 用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(提示:需把用户锁定的状态存到文件里)

dic={
'aaa':{'pw':'123','count':0},
'bbb':{'pw':'234','count':0},
'ccc':{'pw':'456','count':0}
}
tag=True
count=0
while tag:
un=input('your username>>>')
if not un in dic:
print('non username')
count+=1
if un in dic:
pw = input('your password>>>')
if pw == dic[un]['pw']:
print('welcome')
break
else:
print('password error')
count+= 1
if count > 2:
print('account blocked')
break

猜你喜欢

转载自www.cnblogs.com/du-jun/p/9649071.html