python 招聘 海鹽 python多級選單

2021-10-19 20:27:21 字數 3202 閱讀 3008

該樓層疑似違規已被系統摺疊 隱藏此樓檢視此樓

**:**:

dic_china = {

"直轄市":{

"北京市":["東城區","西城區","崇文區","宣武區","朝陽區","海淀區","豐台區",

"石景山區","門頭溝區","房山區","通州區","順義區","昌平區","大興區",

"懷柔區","平谷區","延慶縣","密雲縣",],

"省":{

"浙江省":{

"杭州市":["拱墅區","上城區","下城區","江乾區","西湖區","濱江區","蕭山區","餘杭區","建德市","富陽市",

"臨安市","桐廬縣","淳安縣"],

"寧波市":["海曙區","江東區","江北區","北侖區","鎮海區","鄞州區","余姚市","慈溪市","奉化市","象山縣",

"寧海縣"],

"溫州市":["鹿城區","龍灣區","甌海區","瑞安市","樂清市","洞頭縣","永嘉縣","平陽縣","蒼南縣","文成縣",

"泰順縣"],

"嘉興市":["南湖區","秀洲區","海寧市","平湖市","桐鄉市","嘉善縣","海鹽縣"],

"湖州市":["吳興區","南潯區","德清縣","長興縣","安吉縣"],

"紹興市":["越城區","諸暨市","上虞市","嵊州市","紹興縣","新昌縣"],

"金華市":["婺城區","金東區","蘭溪市","義烏市","東陽市","永康市","武義縣","浦江縣","磐安縣"],

print('歡迎使用中國省市查詢工具'.center(30,'-'))

while true:

#---------遍歷字典china,並編號輸出城市分類資訊------

for i,j in enumerate(dic_china,1):

print(i,j)

classify_num = input('請選擇想要檢視的城市分類的編號[退出:q]:')

#---------判斷輸入編號是否正確----------

if classify_num.isdigit():

classify_num = int(classify_num)

if 1 <= classify_num <= len(dic_china):

#---------將客戶選擇的類別的城市資訊存入新的字典中----------

province_municipality_list = list(dic_china.keys())

#---------判斷客戶是選擇額直轄市類-------

if province_municipality_list[classify_num-1] == '直轄市':

dic_municipality = dic_china[province_municipality_list[classify_num-1]]

print(''.center(50, '-'))

for i, j in enumerate(dic_municipality, 1):

print(i, j)

#---------判斷輸入編號是否正確----------

if municipality_num.isdigit():

municipality_num = int(municipality_num)

if 1 <= municipality_num <= len(dic_municipality):

municipality_list = list(dic_municipality.keys())

county_list = dic_municipality[municipality_list[municipality_num-1]]

print('以下是該直轄市下所有區的資訊:')

print(county_list)

elif municipality_num.upper() == 'q':

print(''.center(50,'-'))

else:

print('輸入錯誤,請重新輸入!!')

else:

dic_province = dic_china[province_municipality_list[classify_num-1]]

print(''.center(50, '-'))

#---------遍歷字典dic_province,並編號輸出省級城市資訊---------

for i, j in enumerate(dic_province, 1):

print(i, j)

# ---------判斷輸入編號是否正確----------

if province_num.isdigit():

province_num = int(province_num)

if 1<= province_num <= len(dic_province):

# ---------將客戶選擇的市資訊存入新的字典中----------

province_list = list(dic_province.keys())

dic_city = dic_province[province_list[province_num-1]]

print(''.center(50, '-'))

for i, j in enumerate(dic_city, 1):

print(i, j)

if city_num.isdigit():

city_num = int(city_num)

if 1 <= city_num <= len(dic_city):

city_list = list(dic_city.key())---------------------------->問題在這!!!!!!!!!!!!!

elif province_num.upper() == 'q':

print(''.center(50,'-'))

else:

print('輸入錯誤,請重新輸入!!')

else:

print('輸入的編號不在城市分類的編號範圍內,請重新輸入!!')

elif classify_num.upper() == 'q':

else:

print('輸入錯誤,請重新輸入!!')

問題:**中標紅的位置,查詢字典dic_city的key值存入city_list列表中,但是key方法無法使用,

求大神們給我解答下

Python學習筆記 1 1 2 認識Python

一.課程目標 二.詳情解讀 1.初識pythonpython語言是一種高階程式語言,它於1991年由吉多.範羅蘇姆 guido van rossum 發明。目前主要應用於web開發 gui開發 網路爬蟲 資料科學 人工智慧等領域。python官方 python語言也是一種多正規化程式語言,即物件導向...

python實現演算法 kmp演算法python實現

kmp演算法python實現 kmp演算法 kmp演算法用於字串的模式匹配,也就是找到模式字串在目標字串的第一次出現的位置 比如abababc 那麼bab在其位置1處,bc在其位置5處 我們首先想到的最簡單的辦法就是蠻力的乙個字元乙個字元的匹配,但那樣的時間複雜度會是o m n kmp演算法保證了時...

python呼叫qt Qt 下呼叫 Python

qt是乙個跨平台的c 圖形使用者介面應用程式框架,而python是一門非常強大的程式語言,本文主要介紹了如何在osx系統下qt呼叫python指令碼。先上 include 包含呼叫python相應的標頭檔案 include int main int argc,char ar 初始化python直譯器...