Python - 三级菜单优化方法 (单层循环)

 1 menu = {
...... 43 } 44 current_layer = menu 45 layers = [] 46 while True: 47 for k in current_layer: 48 print(k) 49 choice = input('>:').strip() 50 if not choice:continue 51 if choice in current_layer: 52 layers.append(current_layer) 53 current_layer = current_layer[choice] 54 elif choice == 'q': 55 break 56 elif choice == 'b': 57 if len(layers) != 0: 58 current_layer = layers.pop() 59 else: 60 print('-------Top!-------')

猜你喜欢

转载自www.cnblogs.com/91joe/p/10773982.html
今日推荐