Class Exercise: Python-Level 3 menu,
#! /Usr/bin/env python # _ authon bruce # @ date: Jun /09/09 15: 47 menu = {"Jiangxi": {"Ganzhou": {"Xingguo ":{}, "yudu" :{}}, "Nanchang" :{}, "Ji 'an" :{}, "Shanghai" :{" Minhang ":{" xinzhuang ":{}, "Qibao" :{}}, "Songjiang" :{},}}current_layer = menu # Implement Dynamic Loop parent_layers = [] # Save all parent levels, the last one will always be the parent while True: for key in current_layer: print (key) choice = input ("> :"). strip () if len (choice) = 0: continue if choice in current_layer: parent_layers.append (current_layer) # before entering the next layer, append the current layer to the parent variable current_layer = current_layer [choice] elif choice = "B": if parent_layers: current_layer = parent_layers.pop () # retrieve the last value of the parent variable as the parent else: print ("NONE") of the current layer ")