Python第二章課後作業,python第二章課後

來源:互聯網
上載者:User

Python第二章課後作業,python第二章課後

2-1簡單資訊:

message="hello world"print(message)

運行結果:


2-2多條簡單資訊:

message="hello world"print(message)message="no thanks"print(message)

運行結果:


2-3個人化資訊:

name="Ro bo"print("hello, "+name+", Good morning!")

運行結果:


2-4調整名字大小寫:

name="Ro bo"print("hello, "+name.lower()+", Good morning!")print("hello, "+name.upper()+", Good morning!")print("hello, "+name.title()+", Good morning!")

運行結果:


2-5名言:

print('Dresser said:"The ideal is the sun of life."')

運行結果:


2-6名言2:

famous_person="Dresser"message='"The ideal is the sun of life."'print(famous_person+" said: "+message)

運行結果:


2-7剔除人名中的空白:

famous_person="\nDresser\t"print("origin:")print(famous_person)print("lstrip")print(famous_person.lstrip())print("rstrip")print(famous_person.rstrip())print("strip")print(famous_person.strip())

運行結果:


2-8數字8:


print(4+4)print(9-1)print(2*4)print(int(16/2))

運行結果:



2-9最喜歡的數字:

number=8print("My favourite number is "+str(number)+"!")

運行結果:


2-10添加註釋:

#列表中的每個元素都是value的三次方arr=[value**3 for value in range(1,5)]print(arr)
#某些數學函數arr=[]for item in range(1,11):arr.append(item)print(arr)print(min(arr))#最小值print(max(arr))#最大值print(sum(arr))#求和

2-11Python之禪:

運行結果:





相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.