使用使用者輸入來填充字典

2021-10-17 19:09:45 字數 1450 閱讀 4409

首先定義乙個空字典(responses),並設定了乙個標誌(polling_active),用於指出迴圈是否繼續。當polling_active為true,python就執行while迴圈中的**。

**如下:

responses =

# 設定乙個標誌,指出調查是否繼續

polling_active =

true

while polling_active:

# 提示輸入被調查者的名字和回答

name =

input

("\nwhat is your name? "

) response =

input

("which mountain would you like to climb someday? "

)# 將答卷儲存在字典中

responses[name]

= response

# 看看是否還有人要參與調查

repeat =

input

("would you like to let another person respond? (yes/ no) "

)if repeat ==

'no'

: polling_active =

false

# 調查結束,顯示結果

print

("\n---poll results ---"

)for name ,response in responses.items():

print

(name +

"would like to climb "

+ response +

".")

執行結果示例:

what is your name? tom

which mountain would you like to climb someday? denali

would you like to let another person respond? (yes/ no) yes

what is your name? lynn

which mountain would you like to climb someday? devil's thumb

would you like to let another person respond? (yes/ no) no--

-poll results ---

tomwould like to climb denali.

lynnwould like to climb devil's thumb.

process finished with exit code 0

摸索學習,尋求進步

摘自《python程式設計 從入門到實踐》——eric matthes著

使用使用者控制項(1)

3.2.2 使用使用者控制項 1 asp.net提供了使用者自定義控制項機制來封裝某些獨立的功能,或者是頁面的某個模組。通過這些封裝,使頁面 更加結構化,也提高了頁面 的復用性。1.基礎知識 control指令和 register指令 asp.net使用者控制項的頁面指令是 control。與web...

Linux expect使用,使用者互動的福音

經常遇到linux需要使用者互動的操作,而且是大量的重複操作,所以。expect 解決你的問題 如下就是乙個簡單的例子 寫個login.sh usr bin expect set timeout 100 set password 123 spawn ssh uname hostname expect...

MOSS開發 如何使用使用者控制項

如果是純手工開發web part,其實還是比較困難的,因為這種型別的web part是以類庫的形式出現,沒有視覺化的介面,完全由 寫出來,包含控制項的樣式,屬性,事件等等。開發過自定義控制項的朋友可能會感受深一些,所以在asp.net應用程式中,開發員從來不開發自定義控制項也非常常見。這種純 的開發...