2021-05-05 17:13:49 +00:00
|
|
|
---
|
|
|
|
id: 5e7b9f070b6c005b0e76f05e
|
2021-06-23 16:05:24 +00:00
|
|
|
title: '迭代:循環成語'
|
2021-05-05 17:13:49 +00:00
|
|
|
challengeType: 11
|
|
|
|
videoId: AelGAcoMXbI
|
2021-10-03 19:24:27 +00:00
|
|
|
bilibiliIds:
|
|
|
|
aid: 334491369
|
|
|
|
bvid: BV1tw411R7Mm
|
|
|
|
cid: 376530765
|
2021-05-05 17:13:49 +00:00
|
|
|
dashedName: iterations-loop-idioms
|
|
|
|
---
|
|
|
|
|
|
|
|
# --question--
|
|
|
|
|
|
|
|
## --text--
|
|
|
|
|
2021-06-23 16:05:24 +00:00
|
|
|
以下是一個如何在一串數值中找到最小的數值的代碼。 一行代碼有錯誤,導致整個代碼無法和預期一樣的運行。 那麼是哪一行?
|
2021-05-05 17:13:49 +00:00
|
|
|
|
|
|
|
```python
|
|
|
|
smallest = None
|
|
|
|
print("Before:", smallest)
|
|
|
|
for itervar in [3, 41, 12, 9, 74, 15]:
|
|
|
|
if smallest is None or itervar < smallest:
|
|
|
|
smallest = itervar
|
|
|
|
break
|
|
|
|
print("Loop:", itervar, smallest)
|
|
|
|
print("Smallest:", smallest)
|
|
|
|
```
|
|
|
|
|
|
|
|
## --answers--
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
## --video-solution--
|
|
|
|
|
|
|
|
3
|
|
|
|
|