#!/usr/bin/env python
Relation ={#创建一个字典"Family":{ "Father":["Atmospheric Stability","a good father in the world"], "Mother":["Gentle and virtuous","a good mother in the world"], }, "friend":{ "TMO":["high-end atmosphere","A sense of loyalty"], "Ming":["happy teasing.","Funny"] }, "School":{ "Mimi":["straightforward personality","refreshing"], "Dede":["Foolhardy","Stay"] }} whileTrue: #第一层 forIinchrelation: #打印第一层Print(i) a= Input ("option 1:") #让用户选择并保存值ifAinchrelation: #判断字典里面有没有用户输入的值 whileTrue: #第二层 forI2inchRelation[a]: #打印第二层Print(i2) b= Input ("Please select: (Return to the previous layer, press S, Exit press Q)") #让用户输入并保存值ifBinchRelation[a]: #判断第二层有没有用户输入的值 whileTrue: #第三层 Select= Input ("View character Press 0, view comments by 1; Go to the previous level press S, exit please press q>>>") #让用户选择并记录ifselect.isdigit (): #判断用户输入是否是数字 Select=int (select) #如果是就转换数据类型ifselect = =0:Print(Relation[a] [b] [select]) #如果用户选择的是family [father] [0] print "atmospheric stability"elifselect = = 1: Print(Relation[a] [b] [select]) #和上面一个道理elifselect = ='Q': #q就退出 exit ()elifselect = ="s": #break返回上一个循环相当于返回上一层 Break Else: Print("Please select 0 or 1;q is exit, s return to the previous level") elifselect = ='Q': Exit ()elifselect = ='s': Break Else: Print("Please enter 0 and 1;q is exit, s return to the previous level") elifb = ="s": Break Else: Print("without this option re-enter!!!;Q is exited and s returns to the upper level") elifA = ='Q': Exit ()Else: Print("without this option re-entering!!!;Q is exiting")
Statement usage for dictionaries
#! /usr/bin/env python#-*-coding:utf-8-*-#Author: Feng Haimei" "info = {' 1 ': "FHM", ' 2 ': "Ghj", ' 3 ': "GED", ' 4 ': "Ydh"}info1 = {' 1 ': "FHM", ' 5 ': "100", ' 7 ': "2 0 "}" "#C = Dict.fromkeys ([5,6,7], ' tist ') #新初始化一个列表#print (c)#print (Info.items ()) Change the dictionary to a list#info.update (INFO1) #合并 have the same value overlay, no add#Print (info["1"]) #索引根据key索引#Print (Info.get ("5")) #索引字典里有这个值就返回数据, no show none, no error#Print ("5" in info) #判读字典里面有没有5这个key#info["1"]= "FHM" #根据key改名字#info["5"]= "zly" If key does not have a value of 5 he will add a#del info["1"] #删除#Info.pop ("1") #删除#Info.popitem () #随机删#For I in info: #字典循环#print (I,info[i])
Python--------Level Three menu implementation