亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

檢查我的 Python 代碼并建議我進行所需的編輯

檢查我的 Python 代碼并建議我進行所需的編輯

紅糖糍粑 2024-01-27 16:06:12
我剛剛開始學習Python。我正在嘗試學習制作一個程序,詢問用戶的姓名和他們想要訪問的地點。并在調查結束時顯示結果。但是,如果用戶選擇將調查傳遞給其他用戶,則顯示的投票結果僅包含回答這些問題的最后一個用戶的姓名和地點。我該怎么做才能使程序顯示所有參與投票的用戶的結果。(代碼是不言自明的)print("Hello world")qstn_1="What is your name?\t"qstn_2="Where would you like to GO for vacation?\t"polling_active=Truewhile polling_active: name=input(qstn_1) place=input(qstn_2) other=input("Would you like other person to answer these survey questions ?\t\n") polling_active=False if other=='yes':      polling_active=True else:    polling_active=False           print("\n\n\t\t\tPOLLING RESULTS\n")print("\n\n\t" + name.title() + " would like to go to " + place + " for a vacation!\n")
查看完整描述

2 回答

?
慕村9548890

TA貢獻1884條經驗 獲得超4個贊

count = 0

names = []

places = []

while True:

    choice = input("Type N to take survey, type Y to pass it other user :")

    if choice == 'Y' and count==0:

        print("No one has taken this survey")

        break



    elif choice == 'N':

        name = input("What is your name :")

        place = input("Where would you like to visit :")

        names.append(name)

        places.append(place)

        count += 1    


    elif choice == 'Y':

        print("The last user was", names[-1], "and", names[-1], "wanted to visit", places[-1])

        break


print("\n\n\t\t POLLING RESULTS\n")

for name, place in zip(names, places):

    print(name, "wanted to visit", place,"\n")


查看完整回答
反對 回復 2024-01-27
?
慕哥6287543

TA貢獻1831條經驗 獲得超10個贊

一些修復:


添加了列表,最后需要解壓列表。

print("Hello world")

qstn_1="What is your name?\t"

qstn_2="Where would you like to GO for vacation?\t"

polling_active=True

name_lst = []

place_lst = []

while polling_active:

    name_lst.append(input(qstn_1))

    place_lst.append(input(qstn_2))

    other=input("Would you like other person to answer these survey questions ?\t\n")

    polling_active=False

    if other=='yes':

        polling_active=True


      

    

print("\n\n\t\t\tPOLLING RESULTS\n")

for i_name, i_place in zip(name_lst, place_lst):

    print("\n\n\t" + i_name.title() + " would like to go to " + i_place + " for a vacation!\n")



查看完整回答
反對 回復 2024-01-27
  • 2 回答
  • 0 關注
  • 221 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號