Planning & pseudocode
Plan before you code
- An algorithm is a clear list of steps that solves a problem.
- Good programmers plan the steps before they type code.
- A plan helps you spot mistakes early and explain your idea.
코딩 전 계획 수립 (Plan before you code)
- 알고리즘은 문제를 해결하는 명확한 단계 목록입니다.
- 좋은 프로그래머들은 코드를 입력하기 전에 단계를 미리 계획합니다.
- 계획은 초기 오류 발견과 아이디어 설명에 도움을 줍니다.
Decomposition
- Decomposition means breaking a big problem into smaller parts.
- Solve each small part on its own.
- Small parts are easier to write, test, and fix.
분해 (Decomposition)
- **분해(decomposition)**란 큰 문제를 더 작은 부분으로 나누어 해결하는 것입니다.
- 각 작은 부분을 독립적으로 해결하십시오.
- 작은 부분은 작성, 테스트, 수정하기 더 쉽습니다.
Abstraction
- Abstraction means keeping only the details that matter.
- You hide the parts you do not need right now.
- A map is an abstraction: it shows roads, not every tree.
추상화
- 추상화란 중요한 세부 사항만 남기고 나머지는 배제하는 것입니다.
- 현재 필요하지 않은 부분을 숨깁니다.
- 지도는 추상화의 예입니다: 모든 나무가 아닌 도로만 보여줍니다.
Structured English
- Structured English writes the steps as plain numbered sentences.
- It is not real code, so anyone can read it.
구조적 영어
- 구조적 영어는 단계를 번호 매겨진 평범한 문장으로 서술합니다.
- 실제 코드와 다르므로 누구나 쉽게 읽을 수 있습니다.
1. Read the number.
2. If it can be divided by 2 with no remainder, it is even.
3. Otherwise it is odd.
4. Output the answer.
Flowcharts
- A flowchart draws the steps as boxes joined by arrows.
- A rectangle is a step; a diamond is a decision (yes / no).
흐름도
- 흐름도는 화살표로 연결된 상자 형태로 단계를 시각화합니다.
- 사각형은 단계이며, 마름모는 결정(예/아니오)을 나타냅니다.
( start )
|
[ read n ]
|
< n > 0 ? > --no--> [ output "not positive" ]
| yes
[ output "positive" ]
|
( end )
Three building blocks
- Sequence: steps run one after another.
- Selection:
if/elif/elsechooses a path. - Iteration:
for/whilerepeats steps.
세 가지 핵심 요소
- 순서: 단계가 하나씩 이어져 실행됩니다.
- 선택:
if/elif/else이 경로를 선택합니다. - 반복:
for/while이 단계를 반복합니다.
In Cambridge pseudocode
- The same plan in pseudocode, then in Python below.
캐미지아 가위코드에서
- 위 계획의 가상 코드와 이를 Python으로 구현한 코드입니다.
Total ← 0
FOR I ← 0 TO LENGTH(Numbers) - 1
Total ← Total + Numbers[I]
NEXT I
Average ← Total / LENGTH(Numbers)
OUTPUT Average
numbers = [4, 8, 6]
total = 0
for n in numbers:
total = total + n
average = total / len(numbers)
print(average)
Common mistakes
- Pseudocode is a plan in plain words — it does not have to run.
- Break the problem into small steps before you write any code.
- Plan the input → process → output.
흔한 실수
- 가상 코드는 자연어로 작성된 계획이며, 반드시 실행될 필요는 없습니다.
- 코드를 쓰기 전에 문제를 작은 단계로 나누어 보십시오.
- 입력 → 처리 → 출력 흐름을 설계하십시오.
Now you try
- Each task gives you a plan in words. Turn it into Python.
- Press Check answer to test your code.
이제 직접 해보기
- 각 과제는 자연어 계획으로 주어집니다. 이를 Python으로 변환하십시오.
- Answer 확인 버튼을 눌러 코드를 테스트하세요.
An algorithm is ordered steps
Pseudocode is just the steps in order, before you write real code.
Follow this plan: read a whole number; if it divides by 2 with no remainder print Even, otherwise print Odd. For input 4, print Even.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Follow this plan: read a number N; add up every whole number from 1 to N; print the total. For input 5, print 15.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Decompose this into a function. Write count_vowels(word) that returns how many letters of word are vowels (a e i o u, lowercase).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Follow this plan for every number from 1 to 15: if it divides by both 3 and 5, print FizzBuzz; else if it divides by 3, print Fizz; else if it divides by 5, print Buzz; otherwise print the number.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.