python程式設計從基礎到實踐第四章

qq_41799025發表於2020-10-18

課堂學習

students = ['賈克斯','科加斯','拉克絲','金克斯','吉格斯']
#unexpected indent,不必要的縮排
	#print(students)
for student in students:
	print(student) #expected an indented block:期望一個縮排的塊
maginc = ['alice','jiakesi','kejiasi','jinkesi','jigesi']
for people in maginc:
	print(f"The\t{people}\tis\ta\tgreat\tteacher")
	print(f"It\twai\ta great patty, if you think so? {people.title()}")
	print(f"It\twai\ta great patty, if you think so? {people.title()}\n")#這裡換行的意思是把迴圈一遍後空一行再迴圈
print("it was a great show!")
animals = ['dog','cat','duck','pig']
for animal in animals:
	print(f"l love {animal}")
	print("it is our friends!")
print("they are delicious!")
for value in range(1,5):
	print(value)#差1行為,在倒數第二個數時結束執行
number = list(range(1,6))#list是把數字轉為列表
print(number)
twice = list(range(2,11,2))#從2到11,依次加2,直到數字達到或超過11
print(twice)
squares = []
for value in range(1,11):
	squares.append(value ** 2)
print(squares)
print(min(squares))
print(max(squares))
print(sum(squares))
squares = [value**2 for value in range(1,12)]
print(squares)
#max_number = list(range(1,1000_000))
#for value in max_number:
#	print(value)
#print(min(max_number))
#print(sum(max_number))
three_times = [value for value in range(1,21,2)]
print(three_times)
three_times = [value for value in range(3,33,3)]
print(three_times)
li_fang = [value**3 for value in range(1,11)]
print(li_fang)

相關文章