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=8
print("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之禪:

運行結果:





發佈了33 篇原創文章 · 獲贊 0 · 訪問量 9017
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章