经典案例【Python】
2021-06-27 20:06
标签:pen while 存在 bre NPU get enum 16px font 查询 添加 经典案例【Python】 标签:pen while 存在 bre NPU get enum 16px font 原文地址:https://www.cnblogs.com/huohu66888/p/9651025.htmldic = {
‘植物‘: {‘草本植物‘:
[‘冬播‘, ‘春播‘, ‘二月兰‘, ‘紫罗兰‘, ‘洋葱‘, ‘小麦‘],
‘木本植物‘:
[‘松‘, ‘彬‘, ‘樟树‘, ‘乔木‘],
‘藤本本植‘:
[‘扁豆‘, ‘牵牛花‘, ‘芸豆‘, ‘爬山虎‘]
},
‘动物‘: {‘两栖动物‘:
[‘蛙类‘, ‘蟾蜍‘, ‘大鲵‘],
‘哺乳类动物‘:
[‘猫‘, ‘狗‘, ‘猪‘],
‘爬行动物‘:
[‘鳄鱼‘, ‘蛇‘, ‘大螃蟹哈哈‘, ‘知了‘]
},
}
li = []
go = True
while go:
for i, v in enumerate(dic, 1):
print(i, v)
li.append(v)
u_c = str(input(‘>>>‘))
if u_c.isdigit():
u_c = int(u_c)
li1 = []
while go:
for i, v in enumerate(dic[li[u_c - 1]], 1):
print(i, v)
li1.append(v)
u_c1 = input(‘>>>‘)
u_c1 = int(u_c1)
while go:
for i in dic[li[u_c - 1]][li1[u_c1 - 1]]:
print(i)
u_c2 = str(input(‘>>>‘))
u_c2 = u_c2.lower()
if u_c2 == ‘b‘:
li1.clear()
# del li[:] 都是清空的意思
break
elif u_c2 == ‘q‘:
go = False
break
elif u_c.isalpha():
u_c.lower()
if u_c == ‘i‘:
lx = input(‘类型:‘)
if dic.get(lx, 1) == 1:
dic[lx] = {}
zl = input(‘种类‘)
if dic[lx].get(zl, 1) == 1:
dic[lx][zl] = []
while True:
mc = input(‘名称‘)
if mc == ‘q‘:
li.clear()
break
if mc in dic[lx][zl]:
print(‘已经存在‘)
else:
dic[lx][zl].append(mc)