1.输入用户名,密码,并且3次失败后结束。
for i in range(1,4,1):
user_name=input(“user_name:”)
pass_word=input(“pass_word:”)
if i3:
print(“You have tried to many times.”)
elif pass_word"123":
print(“Welcome to the new world.”)
break
else:
print(“You can try agin.”)
2.多级菜单
三级菜单,能选择进入各个子菜单。
(这个时候YBY教会了我用字典)
‘’’
输入b返回上一级,输入q退出程序,输入其他内容则进入目录且可继续输入。
‘’’
date = {‘北京’:{
‘海淀’:{‘北理’,‘北交’},
‘朝阳’:{‘朝阳群众’,‘吃瓜群众’},
‘丰台’:{‘北电’,‘万达’}
},
‘山西’:{
‘运城’:{‘万荣’,‘盐湖’,‘河津’},
‘太原’:{‘中北’,‘太理’}
}
}
exit_flag = False
while True:
for i in date:
print(i)
choice = input(“选择进入>>>>>>”)
if choice in date:
while not exit_flag:
for i2 in date[choice]:
print("\t\t",i2)
choice2 = input(“选择进入2>>>>>>”)
if choice2 in date[choice] :
while not exit_flag :
for i3 in date[choice][choice2]:
print("\t\t",i3)
choice3 = input(“选择进入3>>>>>”)
if choice3 in date[choice][choice2]:
for i4 in date[choice][choice2][choice3]:
print("\t\t",i4)
choice4 = input(“这里是最后一层,输入b返回”)
if choice4 == “b”:
pass
elif choice4 == “q”:
exit_flag = True
if choice3 == “b”:
break
elif choice3 == “q”:
exit_flag = True
if choice2 == “b”:
break
elif choice2 == “q”:
exit_flag = True
elif choice == “q”:
break
这里缩进问题搞得我焦头烂额,必须注意的是if跟choice是同级的。