---
# System prepended metadata

title: 'W06: 3/21'

---

W06: 3/21
===

以上週作業為例，解析迴圈運作。

### Ex1:
```
a = [3,2,7,4,6]
y = 0
for x in a:
  y = y+x
print(y)
```

|     | 1   | 2   | 3   | 4   | 5   | final |
| --- | --- | --- | --- | --- | --- | ----- |
| x   | 3   | 2   | 7   | 4   | 6   |       |
| y   | 3   | 5   | 12  | 16  | 22  | 22    |

`a=[3,2,7,4,6]`

### Ex2:

```
a=[3,2,7,4,6]
y=0
z=0
a.append(9)
for x in a:
  z+=x #x累加
  print(f"x: {x}") #過程
  print(f"y: {y}")
  print(f"z: {z}")
  print(f"a: {a}")
  print("------")
   
print("final result:") #結果
print(f"x: {x}")
print(f"y: {y}")
print(f"z: {z}")
print(f"a: {a}")
```

|     | 1   | 2   | 3   | 4   | 5   | 6   | final |
| --- | --- | --- | --- | --- | --- | --- | ----- |
| x   | 3   | 2   | 7   | 4   | 6   | 9   |       |
| y   | 0   | 0   | 0   | 0   | 0   | 0   | 0     |
| z   | 3   | 5   | 12  | 16  | 22  | 31  | 31    |

`a=[3,2,7,4,6,9]`