Level 4: First Text Code
Python for beginners · grades 6–7
Works in the UK and the US. This version uses US words and grades. The UK version uses UK school years (KS3, Year 7). · UK version of this page
Your first steps in a real text programming language. Six short lessons, about 15 minutes each, that build up to programs which read input, do the math and make decisions. Python runs right here in your browser, so there's nothing to install.
Before you start
- Run is free: press it as often as you like to see what your code does.
- Check grades your answer against tests. Some tests are hidden, so make your program work for any input, not just the example.
- When a task reads input, Classfern types the answers in for you when it checks your program. You can add a message too, like
input("Your name? "). - Stuck? Mr Babbage gives a hint about the part that went wrong.
Graded by Classfern in the browser – a practice check, not a test. Your code is saved in this browser only. It runs in a locked box that can't reach the internet, and we never see it. Please don't put your real name, address or school in your code; a made-up name like "Sam" works just as well.
Lesson 1: Joining text and numbers
By the end you can:
- Join pieces of text with +
- Turn a number into text with str() before joining it
- Use an f-string to put variables into a sentence
Mr Babbage: Welcome to text code! Today we join words and numbers. Python's + only joins text to text, so a number needs str() first. Predict what will be printed before you press Run.
Lesson 1 opens here. It needs JavaScript switched on.
Lesson 2: Changing and swapping variables
By the end you can:
- Change a variable's value, with = and with +=
- Explain why a variable holds only one value at a time
- Swap two variables safely
Mr Babbage: A variable is a labeled box that holds one value at a time. Put a new value in and the old one is gone. Trace each line with your finger, and remember: swapping needs a spare box.
Lesson 2 opens here. It needs JavaScript switched on.
Lesson 3: Data types and casting
By the end you can:
- Tell int, float, str and bool apart
- Explain why input() always gives text
- Convert values with int(), float() and str()
Mr Babbage: Every value has a type: int for whole numbers, float for decimals, str for text and bool for True or False. input() always gives text, so turn it into a number before you do math with it.
Lesson 3 opens here. It needs JavaScript switched on.
Lesson 4: Arithmetic operators
By the end you can:
- Use // for whole-number division and % for the remainder
- Use ** for powers
- Predict results using the order of operations (PEMDAS)
Mr Babbage: My engine loved sums! Today: // shares out whole amounts, % finds what's left over and ** makes powers. Python follows PEMDAS, just like your math classes.
Lesson 4 opens here. It needs JavaScript switched on.
Lesson 5: Input, process, output
By the end you can:
- Read numbers typed by the user
- Turn a formula into a line of Python
- Print a clear result
Mr Babbage: Nearly every program does three things: input (read), process (calculate) and output (print). Today you'll build small calculators. Read the formula carefully and copy it into Python exactly.
Lesson 5 opens here. It needs JavaScript switched on.
Lesson 6: if / elif / else
By the end you can:
- Choose between several cases with if, elif and else
- Put the conditions in the right order
- Test the boundary values
Mr Babbage: Now your programs make decisions. Python checks if, then each elif, then else, from the top, and runs only the first one that's True. So the order matters. Test the edges, like exactly 15 or 16.
Lesson 6 opens here. It needs JavaScript switched on.
Level check
Finished all six? The level check mixes questions from every lesson. Pass with 70% or more to move up to Level 5 when it opens.
The level check opens here. It needs JavaScript switched on.
For teachers and parents
Use a lesson as a bell ringer, homework or a station in a rotation. Students need no account. Progress is kept in their own browser and shown by level and skill. Students who have only used blocks before are welcome: Lesson 1 starts from print().
Standards alignment
| Lesson | CSTA K–12 CS Standards, grades 6–8 |
|---|---|
| 1. Joining text and numbers | 2-AP-11 |
| 2. Changing and swapping variables | 2-AP-11 |
| 3. Data types and casting | 2-AP-11 |
| 4. Arithmetic operators | 2-AP-11 |
| 5. Input, process, output | 2-AP-13 |
| 6. if / elif / else | 2-AP-12 |
2-AP-11: variables and data types. 2-AP-12: control structures. 2-AP-13: breaking problems into parts. Classfern isn't connected with or endorsed by CSTA.
Python is a registered trademark of the Python Software Foundation. Classfern is independent and is not affiliated with or endorsed by it. AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse, Classfern.
Back to the Programming Department · All Classfern departments