python選單 在Python中建立選單

2021-10-10 10:53:34 字數 1376 閱讀 3917

我正在製作乙個python中的選單,需要:

列印出帶有編號選項的選單

讓使用者輸入乙個編號選項

根據使用者選擇的選項編號,執行特定於該操作的功能。目前,您的功能可以列印出正在執行的檔案。

如果使用者輸入了無效的內容,它會告訴使用者他們這樣做,然後重新顯示選單

使用字典儲存選單選項,選項的編號作為鍵,並顯示該選項的文字作為值。

整個選單系統應該在乙個迴圈內部執行,並允許使用者做出選擇,直到他們選擇退出/退出,此時程式可以結束。

我是python的新手,我無法弄清楚我的**有什麼問題。

到目前為止,這是我的**:

ans=true

while ans:

print (""""

1.add a student

2.delete a student

3.look up student record

4.exit/quit

ans=input("what would you like to do?"

if ans=="1":

print(" student added")

elif ans=="2":

print(" student deleted")

elif ans=="3":

print(" student record found")

elif ans=="4":

print(" goodbye")

elif ans !="":

print(" not valid choice try again")answered

這是他明顯想要的:

menu = {}

menu["1"]="add student."

menu["2"]="delete student."

menu["3"]="find student"

menu["4"]="exit"

while true:

options=menu.keys()

options.sort()

for entry in options:

print entry, menu[entry]

selection=raw_input("please select:")

if selection =="1":

print "add"

elif selection == "2":

print "delete"

elif selection == "3":

print "find"

elif selection == "4":

break

else:

print "unknown option selected!"

python選單類 python多級選單

該樓層疑似違規已被系統摺疊 隱藏此樓檢視此樓 dic china 直轄市 北京市 東城區 西城區 崇文區 宣武區 朝陽區 海淀區 豐台區 石景山區 門頭溝區 房山區 通州區 順義區 昌平區 大興區 懷柔區 平谷區 延慶縣 密雲縣 省 浙江省 杭州市 拱墅區 上城區 下城區 江乾區 西湖區 濱江區 蕭...

python 多級選單 python多級選單

該樓層疑似違規已被系統摺疊 隱藏此樓檢視此樓 dic china 直轄市 北京市 東城區 西城區 崇文區 宣武區 朝陽區 海淀區 豐台區 石景山區 門頭溝區 房山區 通州區 順義區 昌平區 大興區 懷柔區 平谷區 延慶縣 密雲縣 省 浙江省 杭州市 拱墅區 上城區 下城區 江乾區 西湖區 濱江區 蕭...

新增右鍵選單 在vscode中開啟

建立乙個文字檔案,寫入如下的文字 windows registry editor version 5.00 hkey classes root shell vscode open with code icon c program files x86 microsoft vs code code.ex...