Before code comes a plan. Then we write it in Python — a simple, readable language. You can run real Python right here: edit the examples and press Run.
1Algorithms, flowcharts & Python
To solve a problem on a computer, first plan the steps:
- An algorithm is a step-by-step list of instructions in plain language.
- A flowchart is a diagram of those steps using standard shapes (oval = start/end, parallelogram = input/output, rectangle = process, diamond = decision).
Algorithm to add two numbers: 1. Start 2. Read a and b 3. sum = a + b 4. Display sum 5. Stop
Python: IDLE & modes
You write Python in IDLE (or any editor). Two ways to run it:
- Interactive mode — type one line, get the result instantly (good for trying things).
- Script mode — write a whole program in a
.pyfile and run it all at once.
- An algorithm is step-by-step instructions in plain language; a flowchart is their diagram (oval, parallelogram, rectangle, diamond shapes).
- Python is written in IDLE (or any editor).
- Interactive mode runs one line at a time; script mode runs a whole .py file.
2Variables, data types & operators
A variable stores a value; its data type says what kind:
| Type | Example |
|---|---|
| int (whole) | 25 |
| float (decimal) | 3.14 |
| string (text) | "Vidaara" |
Operators: arithmetic + - * /, plus // (whole-number divide), % (remainder), ** (power); and = to assign. Run and edit:
Click Run to execute.
- Data types: int (whole), float (decimal), string (text in quotes).
- Arithmetic: + - * / , and // (whole-number divide), % (remainder), ** (power).
- = assigns a value to a variable, e.g. total = price * qty.
3Input, typecasting & decisions
input() reads text from the user. Because it always returns a string, you typecast it to a number with int() or float():
name = input("Your name: ") # a string
age = int(input("Your age: ")) # typecast to int
print(name, "is", age, "years old")Making decisions
Use if, if-else and if-elif-else (note the colon and indentation). Run this:
Click Run to execute.
- input() reads text (always a string); typecast with int() or float() to do maths.
- Decisions use if, if-else, and if-elif-else.
- Python uses a colon (:) and indentation to mark each block — not braces.
★ Practical: small programs
Using the Python playgrounds:
- Print your name and class on two lines.
- Make two number variables and print their sum, product and remainder.
- Change the 'marks' value and re-run to see different grades print.
- Write the algorithm (in plain steps) for checking if a number is even or odd.
Ready for the chapter test?
Answer 5 questions. Score 60% or more to mark this chapter complete.
Start the test →💡 Log in to save your progress and earn the certificate.