Python入門習題大全 夢想的度假勝地

2021-10-04 21:30:20 字數 1260 閱讀 1689

編寫乙個程式,調查使用者夢想的度假勝地。使用類似於"ifyou could visit one place in the word, where would you go?"的提示, 並編寫乙個列印調查結果的**塊。

# 夢想的度假勝地

places =

prompt =

"what is your name? \n"

prompt +=

"enter 'quit' when you finished. \n"

message =

"if you could visit one place in the world, where would you go? \n"

active =

true

while active:

name =

input

(prompt)

if name ==

'quit'

:break

place =

input

(message)

places[name]

= place

for name, place in places.items():

print

(name +

" wants to go to "

+ place +

".")

輸出為:

(依次輸入 ling,a,huihe,b,quit)

what is your name? 

enter 'quit' when you finished.

ling

if you could visit one place in the world, where would you go?

awhat is your name?

enter 'quit' when you finished.

huihe

if you could visit one place in the world, where would you go?

bwhat is your name?

enter 'quit' when you finished.

quit

ling wants to go to a.

huihe wants to go to b.

process finished with exit code 0

Python入門習題大全 比薩

想出至少三種你喜歡的比薩,將其名稱儲存在乙個列表中,再使用 for 迴圈將每種比薩的名稱都列印出來。1.修改這個 for 迴圈,使其列印包含比薩名稱的句子,而不僅僅是比薩的名稱。對於每種比薩,都顯示一行輸出,如 i like pepperoni pizza 2.在程式末尾新增一行 它不在 for 迴...

Python入門習題大全 切片

隨意建立乙個列表,在末尾新增幾行 以完成如下任務。列印訊息 the first three items in the list ate 再使用切片來列印列表的前三個元素。列印訊息 three items from the middle of the list ate 再使用切片來列印列中間的三個元素...

Python入門習題大全 序數

序數表示位置,如 1st 和 2nd。大多數序數都以 th 結尾,只有 1 2 和 3 例外。在乙個列表中儲存數字 1 9。遍歷這個列表。在迴圈中使用乙個 if elif else 結構,以列印每個數字對應的序數。輸出內容應為 1st 2nd 3rd 4th 5th 6th 7th 8th 和 9t...