按任意鍵選擇,返回,退出

2021-09-08 04:09:26 字數 2020 閱讀 3439

按數字鍵選擇任意城市、地區等,按b返回上一級選單重新選擇,按q退出整個程式

import

syshaidian=['

guotu

','zhongguancun']

chaoyang=['

shoutu

','dayuecheng']

pudong=['

mingzhu

','waitan']

dongfang=['

dong

','fang']

beijing=

shanghai=

city=

while

true:

for x,y in

enumerate(city):

print x+1,y

num_c=raw_input('

please enter a number to choose a city,or press b back to previous menu,or press q to quit:')

if num_c == 'q'

: sys.exit()

if num_c is

not none: #

此處需要細化判斷輸入字元是否合規

for x,y in

enumerate(city):

if x+1 ==int(num_c):

city_choice =y

print

'your choice is : %s

' %city_choice

while

true:

for x,y in

enumerate(city[city_choice]):

print x+1,y

num_d=raw_input('

please enter a number to choose a district,or press b back to previous menu,or press q to quit:')

if num_d == 'q'

: sys.exit()

if num_d == '

b': #

返回到上一級選擇城市的選單

break

if num_d is

notnone:

for x,y in enumerate(city[city_choice]): #

列舉city['beijing']

if x+1 ==int(num_d):

dt_choice =y

print

'your choice is : %s

' %dt_choice

while

true:

for x,y in enumerate(city[city_choice][dt_choice]): #

列舉city['beijing']['haidian']

print x+1,y

num_s=raw_input('

please enter a number to choose a place,or press b back to previous menu,or press q to quit:')

if num_s == 'q'

: sys.exit()

if num_s == '

b': #

返回到上一級選擇地區的選單

break

if num_s is

notnone:

for x,y in

enumerate(city[city_choice][dt_choice]):

if x+1 ==int(num_s):

l_choice =y

print

'your choice is : %s

' %l_choice

用C 實現「按任意鍵繼續」

很久沒有寫過c 程式了,對visual studio有些不習慣。尤其對它編譯後直接退出感到無語到憤怒。於是就谷歌度娘都訪問了一下,發現有幾下方法 1.直接呼叫系統函式 system pause 例如 include using namespace std int main 2.呼叫getch 函式 ...

Python 實現「按任意鍵返回」和無回顯輸入

學python 用rpa www.i search.com.cn index.html?from line1 功能描述 在某些應用場景中,需要實現 按任意鍵返回 這樣的功能,在 python 中如果使用內建函式 input 的話必須有個回車鍵才表示輸入結束,不夠完美。在 msvrct 標準庫中,可以...

C C 實現按下任意鍵繼續功能

當我們在使用系統命令 stop時會在終端下彈出 按下任意鍵繼續的 這裡只需要c c 自帶的函式即可 kbhit 函式原型 int kbhit void 返回值 如果有按鍵按下返回非0否則返回0 函式介紹 此函式是c c 裡的乙個自帶函式,可以用於監視鍵盤輸入事件,當有鍵盤在當前執行緒下按下按鍵時,此...