第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何以任何順序允許多個用戶響應(yīng)?

如何以任何順序允許多個用戶響應(yīng)?

素胚勾勒不出你 2021-11-23 16:15:22
我該怎么解決,以允許用戶輸入'Version','Credit','Info', 'Notes'和'Credit'以任何順序?這是我試過的代碼:if(answer == 'Debug'):    print('Type the word in the debug screen\nto get an output, '          'ex. Type "Version"\nto find the file Version.')print('\033[1;34;40m============')print('\033[1;39;40mVersion')print('\033[1;33;40mCredit')print('\033[1;34;40mInfo')print('\033[1;32;40mNotes')answer=raw_input()if(answer == 'Version'):    print('\033[1;39;39m1.2.2')if(answer == 'Credit'):    print('\033[1;33;40mXendos6 2/22/19')
查看完整描述

2 回答

?
慕容3067478

TA貢獻(xiàn)1773條經(jīng)驗 獲得超3個贊

您可以使用包含每個問題和打印回復(fù)的字典,例如:


menu = {'Version': '1.2.2', 'Credit': 'Xendos6 2/22/19', 'Info': 'Some information'}


print('\033[1;34;40m============')

for k in menu.keys():

    print('\033[1;39;40m', k)


answer = raw_input()

if answer in menu:

    print('\033[1;39;39m', menu[answer])

else:

    print("Invalid answer:", answer)

這使得菜單更容易添加項目。如果要執(zhí)行的代碼比簡單的文本字符串更復(fù)雜,則可以將操作放置在一個函數(shù)中,每個菜單項一個,并將函數(shù)名稱用作值。然后將該函數(shù)稱為menu[answer]()。


編輯:現(xiàn)在看來 OP 需要一個循環(huán)。這是一個示例,它在選擇時從菜單中刪除每個條目:


menu = {'Version': '1.2.2', 'Credit': 'Xendos6 2/22/19', 'Info': 'Some information'}


while menu:

    print('\033[1;34;40m============')

    for k in menu.keys():

        print('\033[1;39;40m', k)


    answer = raw_input()

    if answer in menu:

        print('\033[1;39;39m', menu[answer])

        del(menu[answer])

    else:

        print("Invalid answer:", answer)

這將在選擇項目時刪除鍵。循環(huán)在其中menu有數(shù)據(jù)項時繼續(xù)-為空while menu:時menu為假。


查看完整回答
反對 回復(fù) 2021-11-23
?
紫衣仙女

TA貢獻(xiàn)1839條經(jīng)驗 獲得超15個贊

請看看這個。也許這會解決你的問題。


responses = {

    'version': '1.0.1',

    'credit': 'some_credit',

    'info': 'this is info',

    'debug': 'this is debug output'

}


for i in responses.keys():

    user_input = input('Please enter a choice from {}: '.format(options))

    print(responses.get(user_input))

注意:這只是一個模板


查看完整回答
反對 回復(fù) 2021-11-23
  • 2 回答
  • 0 關(guān)注
  • 188 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號