Bạn đang xem thử công khai
Đăng nhập để lưu tiến độ, làm bài tập, thảo luận và nhận phản hồi.
Review lesson. A summary of the conditionals and loops part of Module 1, for quick reference and self-checking after units 1.7 → 1.8.
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
else:
grade = "C"
else belongs to the nearest if at the same indentation level; pass is a placeholder for a block that has not been written yet.| Need | Use |
|---|---|
| Repeat a known number of times, or go through each element | for |
| Repeat until the condition becomes false | while |
| Exit the loop completely | break |
| Skip the rest of the current iteration | continue |
range(start, end, step) stops right before end: range(2, 6) gives 2, 3, 4, 5.else attached to a loop runs only when the loop is not ended by a break.while loop, remember to update the condition variable; otherwise the loop runs forever.