Preparing Your Program
Describe in Natural Language
Before coding, it is crucial to properly prepare your program. Here are the recommended steps:
- Think about inputs and outputs.
- Break down the problem into sub-problems.
- Write the steps with simple sentences, like a recipe.
- Think about necessary conditions and loops.
- Use bullet points or numbered lists for clarity.
- Don't worry about code syntax.
Example (ROT13 on a letter):
1. Read a letter.
2. Find its position in the alphabet.
3. Add 13 to this position.
4. If we exceed Z, go back to the beginning of the alphabet.
5. Give the new letter.
Translate to Pseudocode
- Pseudocode resembles code but remains independent of a specific language.
- Use simple keywords: IF, THEN, ELSE, FOR, WHILE…
Example (ROT13 on a letter):
Read letter
position ← rank(letter)
new_position ← position + 13
IF new_position > 26 THEN
new_position ← new_position - 26
END IF
Display corresponding_letter(new_position)
Key Points to Remember
- Always start in natural language: clarifies reasoning.
- Then move to pseudocode: structures the logic.
- Finally translate to Python: this is only the last step.