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

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

連續(xù)輸入。

連續(xù)輸入。

一只甜甜圈 2022-06-28 10:25:46
如何進(jìn)行連續(xù)輸入?我希望玩家能夠在他想要的任何時(shí)候編寫菜單,而不僅僅是在程序開始時(shí)?print("\nWelcome to the nature center. What would you like to do?")choice = ''while choice != 'q':    print("\n[1] Enter 1 to take a bicycle ride.")    print("[2] Enter 2 to go for a run.")    print("[3] Enter 3 to climb a mountain.")    print("[q] Enter q to quit.")choice = input("\nWhat would you like to do? ")if choice == '1':     print("\nHere's a bicycle. Have fun!\n")elif choice == '2':    print("\nHere are some running shoes. Run fast!\n")elif choice == '3':    print("\nHere's a map. Can you leave a trip plan for us?\n")elif choice == 'q':    print("\nThanks for playing. See you later.\n")else:    print("\nI don't understand that choice, please try again.\n")
查看完整描述

2 回答

?
郎朗坤

TA貢獻(xiàn)1921條經(jīng)驗(yàn) 獲得超9個(gè)贊

不確定您的縮進(jìn)是否不正確,但您可以永遠(yuǎn)循環(huán)(while True),然后break在您需要時(shí):


print("\nWelcome to the nature center. What would you like to do?")

while True: # Loop through indefinitely

    print("\n[1] Enter 1 to take a bicycle ride.")

    print("[2] Enter 2 to go for a run.")

    print("[3] Enter 3 to climb a mountain.")

    print("[q] Enter q to quit.")


    choice = input("\nWhat would you like to do? ")


    if choice == '1': 

        print("\nHere's a bicycle. Have fun!\n")

    elif choice == '2':

        print("\nHere are some running shoes. Run fast!\n")

    elif choice == '3':

        print("\nHere's a map. Can you leave a trip plan for us?\n")

    elif choice == 'q':

        print("\nThanks for playing. See you later.\n")

        break # Exit the loop here

    else:

        print("\nI don't understand that choice, please try again.\n")

輸出:


Welcome to the nature center. What would you like to do?


[1] Enter 1 to take a bicycle ride.

[2] Enter 2 to go for a run.

[3] Enter 3 to climb a mountain.

[q] Enter q to quit.


What would you like to do? 1


Here's a bicycle. Have fun!



[1] Enter 1 to take a bicycle ride.

[2] Enter 2 to go for a run.

[3] Enter 3 to climb a mountain.

[q] Enter q to quit.


What would you like to do? 2


Here are some running shoes. Run fast!



[1] Enter 1 to take a bicycle ride.

[2] Enter 2 to go for a run.

[3] Enter 3 to climb a mountain.

[q] Enter q to quit.


What would you like to do? q


Thanks for playing. See you later.


查看完整回答
反對 回復(fù) 2022-06-28
?
慕田峪7331174

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊

我認(rèn)為您還需要在您的while:


print("\nWelcome to the nature center. What would you like to do?")

choice = ''

while choice != 'q':

    print("\n[1] Enter 1 to take a bicycle ride.")

    print("[2] Enter 2 to go for a run.")

    print("[3] Enter 3 to climb a mountain.")1

    print("[q] Enter q to quit.")


    choice = input("\nWhat would you like to do? ")


    if choice == '1': 

        print("\nHere's a bicycle. Have fun!\n")

    elif choice == '2':

        print("\nHere are some running shoes. Run fast!\n")

    elif choice == '3':

        print("\nHere's a map. Can you leave a trip plan for us?\n")

    elif choice == 'q':

        print("\nThanks for playing. See you later.\n")

    else:

        print("\nI don't understand that choice, please try again.\n")


查看完整回答
反對 回復(fù) 2022-06-28
  • 2 回答
  • 0 關(guān)注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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