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.
Планируйте перед написанием кода
- Алгоритм — это чёткий список шагов, решающих задачу.
- Хорошие программисты планируют шаги до того, как наберут код.
- План помогает выявить ошибки на ранней стадии и объяснить свою идею.
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.
Декомпозиция
- Декомпозиция означает разделение большой задачи на меньшие части.
- Решайте каждую малую часть отдельно.
- Малые части легче писать, тестировать и исправлять.
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.
В псевдокоде Cambridge
- Тот же план на псевдокоде, а затем в 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.
- Нажмите Check 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. · Нажмите Запустить, чтобы увидеть результат здесь.