playlist for today:
讓程式不斷地執行
獲取使用者輸入並學會控制程式的執行時間,互動式程式
input()
function
name =
input
('enter you name please: '
)print
('good evening, '
+ name +
'!')
hint =
'\npjs kissed toes of a member when he was drunk.'
hint +=
'\nwho is that member? '
answer =
input
(hint)
if answer ==
'ljn'
:print
('\nyes, he kissed '
+ answer
+"'s toes. haha"
)else
:print
("\nsorry, the one pjs kisssed"
+'is not '
+ answer)
使用int()
函式獲得數值輸入
input()
獲得的輸入被自動解讀為字串,無法作為數字使用
numberofhuaren =
answer =
input
('\nnct is limitless, so it expands'
+' every year. \nwhen did you become a haufen? '
)answer =
int(answer)
for year, number in numberofhuaren.items():
if year == answer:
print
('in '
+str
(answer)
+', the number of '
+'huaren is '
+str
(number)
)
求模運算子
%
:將兩個數相除並返回餘數
input
=input
('\nenter the number you want to check: '
)input
=int
(input)if
input%2
==0:print
('the number '
+str
(input)+
' is even'
)else
:print
('the number '
+str
(input)+
' is odd'
)
current_number =
1while current_number <=5:
print
(current_number)
, current_number +=
1# current_number = current_number + 1
讓使用者選擇何時退出
prompt =
'\ntell me something, and i will repeat it back to you: '
prompt +=
"\nenter 'quit' to end the program. "
message =
""while message !=
'quit'
: message =
input
(prompt)
if message !=
'quit'
:#列印訊息前對訊息進行檢查
print
(message)
使用標誌
標誌
使用者輸入和while迴圈
函式input 讓程式暫停執行,等待使用者輸入一些文字。獲取使用者輸入後,python將其儲存在乙個變數中,以方便你使用。函式input 接受乙個引數 即要向使用者顯示的提示 或說明,讓使用者知道該如何做。在這個示例中,python執行第1行 時,使用者將看到提示tell me something,...
使用者輸入和while迴圈
message 這是個示例.message 這也是個示例.aa input message aa int aa print type aa current number 1while current number 10 print current number current number 1pro...
使用者輸入和while迴圈
函式input 的工作原理message input tell me something,and i will repeat it back to you print message 有時,提示可能超過一行,可將提示儲存在乙個變數中,再將該變數傳遞給函式input prompt if you tel...