python 使用者輸入和while迴圈5

2021-10-23 08:45:28 字數 975 閱讀 6415

基本都是c語言的知識,不再贅述

message =

input

("tell me something, and i will repeat it back to you: "

)print

(message)

#結果tell me something,

and i will repeat it back to you: hello everyone!

hello everyone!

下面的while迴圈從1數到5

current_number =

1while current_number <=5:

print

(current_number)

current_number +=

1

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

Python入門筆記 迴圈for和while

while 迴圈 在給定的判斷條件為 true 時執行迴圈體,否則退出迴圈體。for 迴圈 重複執行語句 巢狀迴圈 你可以在while迴圈體中巢狀for迴圈 break 語句 在語句塊執行過程中終止迴圈,並且跳出整個迴圈 continue 語句 在語句塊執行過程中終止當前迴圈,跳出該次迴圈,執行下一...

python請求使用者輸入 使用者輸入

使用者輸入 大多數程式都旨在解決終端使用者的問題,為此通常需要從使用者那裡獲取一些資訊。例如,假設有人要判斷自己是否到了投票的年齡,要編寫回答這個問題的程式,就需要知道使用者的年齡,這樣才能給出 答案。因此,這種程式需要讓使用者輸入其年齡,再將其與投票年齡進行比較,以判斷使用者是否到了投票的年齡,再...

python使用者輸入

使用者輸入 python2.0 name raw input input your name raw input 輸入接收的是字串和數字,python都認為是字串。並賦值給name name input input your age input 輸入接收的是數字和字元,input python認為輸...