日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python第7章实训作业_试图学Python赚外快的第7天

發布時間:2024/9/19 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python第7章实训作业_试图学Python赚外快的第7天 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

感覺吧,越來越多了,今天主要要學while循環的,本來打算一天一章,一本書20章的話很快就搞定了,我覺得還是有點天真了 前邊還好,后邊打的程序查錯?查半天,主要是漢子切換時忘了換回來,標點符號錯的,還有縮進行 感覺把前面注意的通通都犯了一遍,有時候查好幾次,查不出毛病,你就說氣不氣,程序員沒頭發我突然理解了 今天就開始學習吧,硬是留了點小尾巴課后題,圖片就放在后邊不在中間放了哦


第7章:While循環和用戶輸入

1、Input()讓程序能夠暫停,使得用戶可以輸入信息

如下例子:

message=input("Tell me something,and I will repeat it back to you: ")

print(message)

2、如果提示語太長可以使用+=使得信息分行轉化,輸入行只能在+=這一行

name=input("please enter your name: ")

print("Hello, "+name +"!")

prompt = "If you tell us who you are, we can personalize the messages you see."

prompt +="nWhat is your first name? "

name=input(prompt)

print("nHello, "+name+"!")

3、int()輸入數值,不要和str()記混了哦,這個是我們第二章說過的,將非字符串顯示為字符串

height=int(input("How tall are you,in inches?"))

#也可以在這一行寫height=int(hight)

if height >=36:

print("nYou're tall enough to ride!")

else:

print("nYou will be able to ride when you are a little older.")

4、余數運算用%,比如5%4余數為1(求模運算)

下面是輸入一個數顯示為奇數或者偶數

number=int(input("Enter a number, and I'll tell you if it's even or odd:"))

if number%2==0:

print("nThe number "+str(number)+" is even")

else:

print("nThe number "+str(number)+" is odd")

5、使用while循環語句(嗯,while循環就是當條件不滿足時停止,for循環是針對每個元素都要執行遍的)還有布爾表達,開啟程序運行時可以使用哦,當然滿足后要終止程序

#程序1

prompt="nTell me something ,and I'll repeat it back to you:"

prompt+="nEnter quit to end the program:"

message=""

while message!='quit':

message=input(prompt)

print(message) #會有一個quit打印出來

#程序1的改進,程序2

prompt="nTell me something ,and I'll repeat it back to you:"

prompt+="nEnter quit to end the program:"

message=""

while message!='quit':

message=input(prompt)

if message!='quit': #只有當message不等于quit才打印,當meesage等于quit時,就不會出現末尾的quit

print(message)

#程序2的改進,含標志(布爾表達式)

prompt="nTell me something ,and I'll repeat it back to you:"

prompt+="nEnter quit to end the program:"

active='True'

while active:

message=input(prompt)

if message=='quit':

active=False #當message不等于quit時,程序運行不下去,返回接著用戶重新輸入,直到message等于quit時運行打印

else:

print(message)

好了,就到這吧,溜了溜了

總結

以上是生活随笔為你收集整理的python第7章实训作业_试图学Python赚外快的第7天的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。