(标答出处: 鱼C论坛)
《零基础入门学习Python》
测试题:
测试题:
4.请目测下边代码执行后,字典dict1的内容是什么?
dict1.fromkeys((1,2,3),(‘one’,‘two’,‘three’))
dict1.fromkeys((1,3),‘数字’)
5.如果你需要将字典dict1={1:‘one’,2:‘two’,3:‘three’}拷贝到dict2,你应该怎么做?
使用update来进行拷贝
dict2=dict1.copy()
dict2=dict2.update(dict1)
0.尝试些一个用户登录程序(这次尝试将功能封装成函数)
user_data={}
def built_new() :
yonghuming = input ("请输入用户名:")
while yonghuming in user_data :
yonghuming = input ("此用户名已经被使用,请重新输入:")
mima = input ("请输入密码:")
user_data[yonghuming] = mima
print ("注册成功,赶紧试试登陆吧^_^\n")
def land_old() :
yonghuming = input ("请输入用户名:")
while yonghuming not in user_data :
yonghuming = input ("此用户名尚未被注册,请重新输入:")
mima = input ("请输入密码:")
while user_data[yonghuming] != mima :
mima = input ("密码错误,请重新输入:")
print("欢迎进入XXOO系统,请点击右上角的X结束程序!\n")
def main():
temp = True
while temp == True :
print ("|--- 新建用户:N/n ---|")
print ("|--- 登录账号:E/e ---|")
print ("|--- 退出程序: Q/q ---|")
choice = input ("|--- 请输入指令代码:")
if choice=='q' or choice=='Q':
temp = False
elif choice=='n' or choice=='N':
built_new()
elif choice=='e' or choice=='E':
land_old()
else :
print ("您输入的指令不正确,请重新输入!")
main ()