b024: Ch4-14 實例演練
Tags : Python
Accepted rate : 1人/1人 ( 100% ) [非即時]
評分方式:
Tolerant

最近更新 : 2022-11-24 13:40

Content

利用def,建立一個「交換兩數」功能的函數,重新設計4-1節的實例演練,即交換星期日及星期六的動物園遊客人數。

def swap(a, i, j):
       temp = a[i]
       a[i] = a[j]
       a[j] = temp # 不必return
num_visitors = [70, 10, 14, 7, 25, 30, 50] # 索引0~6代表星期日到六
print(num_visitors)
swap(num_visitors, 0, 6) # 把星期日及星期六的人數交換
print(num_visitors)

Input
Output
Sample Input #1


											
										
Sample Output #1
"[70, 10, 14, 7, 25, 30, 50]
[50, 10, 14, 7, 25, 30, 70]"
測資資訊:
記憶體限制: 64 MB
公開 測資點#0 (100%): 1.0s , <1K
Hint :
Tags:
Python
出處:
育達高中資訊科技 [管理者: zero(育達管理員) ]


ID User Problem Subject Hit Post Date
沒有發現任何「解題報告」