LEARN PYTHON | 01 FIRST STEPS
Build it. Test it. Explain it.
Turn your first Python skills into small useful programs. Work independently before opening a hint, then compare your tested solution with one possible approach.
YOUR CHALLENGE ROUTE
Complete these tasks in your Python editor. The page is a challenge guide, not a general Python runner. Use fictional details where helpful. Work in order or choose a task matching an area you need to practise.
The core solutions use Section 1 skills only. They state valid-input assumptions instead of introducing unexplained if statements, loops or exception handling. Observe and record those limitations when testing.
TRACK YOUR TESTED SOLUTIONS
Tick a task only after you have run it, checked at least two relevant cases and explained one line. These are self-recorded checks, not an automatic assessment of your source code.
Progress lasts while this page is open. Save your actual Python files in your project folder.
01 | FOUNDATION
PROVE YOUR SETUP
Create a file that proves you can edit, save, run and reopen a Python program. Choose IDLE or VS Code with the Microsoft Python extension.
YOUR REQUIREMENTS
- Save setup_check.py in your Section 1 folder.
- Print three separate lines: a title, an invented first name and a short coding goal.
- Change the goal, save and run the whole file again.
- Close the editor, reopen the saved file and rerun it.
Hint: where to begin
The source belongs in a .py editor file. In IDLE use Run Module; in VS Code use Run Python File in Terminal. Do not copy the shell’s >>> prompt into your file.
TEST YOUR PROGRAM
| Test input or action | Expected result |
|---|---|
| Initial run | The three messages appear in source order. |
| Change the goal | Only the changed message differs. |
| Reopen and run | The saved version still produces its messages. |
Reveal one possible solution and explanation
print("Python setup check")
print("Name: Maya")
print("Goal: build a robot controller")The editor holds your source instructions; the interpreter executes them. Saving preserves the source, while running produces the output. A changed message confirms you are running the intended file.
A different implementation can also be correct if it meets the requirements and tests. Compare meaning and behaviour, rather than only copying the source.
Extension: Show a partner the source and output. Explain which window accepts code and where the program’s output appears.
02 | FOUNDATION
DESIGN A CONSOLE TICKET
Create a ticket for a fictional coding event. The output should communicate clearly, rather than look like unrelated values.
YOUR REQUIREMENTS
- Print the event title and a blank output line.
- Print a labelled attendee count calculated from 4 + 6.
- Print a closing message.
- Add a useful # comment explaining a purpose.
Hint: where to begin
A blank source line does not print a blank output line. Use print(). Keep 4 + 6 outside quotes when you want its calculated value.
TEST YOUR PROGRAM
| Test input or action | Expected result |
|---|---|
| Attendee total | Expected attendees: 10 |
| Blank line | One empty line follows the title. |
| Comment | The comment is absent from the output. |
Reveal one possible solution and explanation
# Show a readable event ticket
print("Coding Club Open Day")
print()
print("Expected attendees:", 4 + 6)
print("Bring your curiosity!")The comma separates print arguments and normally inserts a space in the output. The arithmetic expression is evaluated before printing; quoted "4 + 6" would print the characters instead.
A different implementation can also be correct if it meets the requirements and tests. Compare meaning and behaviour, rather than only copying the source.
Extension: Add a second labelled calculation for equipment needed. Explain why its answer is meaningful.
03 | REPAIR
REPAIR THE WELCOME PROGRAM
The broken source below is intended to greet the user and display the numeric total 15. Find each issue rather than replacing it without explanation.
YOUR REQUIREMENTS
- Correct the name and paired punctuation.
- Make the total a numeric calculation.
- Keep the useful comment unprinted.
- Explain each correction in your exercise book.
SOURCE TO REPAIR
# Welcome a new coder
Print("Welcome to Python)
print("Total:", "12 + 3"Hint: where to begin
Python names are case-sensitive. Match quotation marks and parentheses. Quotes make an expression into literal text.
TEST YOUR PROGRAM
| Test input or action | Expected result |
|---|---|
| Run repaired source | Welcome to Python, then Total: 15. |
| Change 3 to 5 | The total becomes 17. |
| Explain literal text | "12 + 3" prints text, not the number 15. |
Reveal one possible solution and explanation
# Welcome a new coder
print("Welcome to Python")
print("Total:", 12 + 3)Print is not the built-in print name. An opening quotation mark needs a matching close, and a function call needs its closing parenthesis. Python cannot parse the broken file until its syntax is repaired.
A different implementation can also be correct if it meets the requirements and tests. Compare meaning and behaviour, rather than only copying the source.
Extension: Add a line containing an apostrophe, choosing quotation marks that keep the string valid.
04 | FOUNDATION
BUILD A TYPED PROFILE
Create a fictional learner profile using the four basic Python types introduced in Section 1.
YOUR REQUIREMENTS
- Store a name and code 0072 as strings.
- Store a whole-number project count as int.
- Store fractional practice hours as float.
- Store a completion flag as bool.
- Print a readable report and use type() to inspect each kind.
Hint: where to begin
Digits in an identifier are not necessarily an amount. True and False use capitals and no quotation marks.
TEST YOUR PROGRAM
| Test input or action | Expected result |
|---|---|
| Student code | 0072 retains its leading zeros. |
| Types | str, int, float and bool respectively. |
| Change finished | Changing False to True updates the displayed flag. |
Reveal one possible solution and explanation
username = "Maya"
student_code = "0072"
projects = 3
practice_hours = 2.5
finished = False
print(f"{username} ({student_code}) completed {projects} projects.")
print(f"Practice: {practice_hours} hours; finished: {finished}")
print(type(username), type(projects), type(practice_hours), type(finished))The identifier is text because its exact representation matters. The count is whole-number data; practice can be fractional. A Boolean flag represents two states. Printing False and "False" can look similar, so type() helps distinguish them.
A different implementation can also be correct if it meets the requirements and tests. Compare meaning and behaviour, rather than only copying the source.
Extension: Rename one vague identifier in your own solution. Explain how the new name improves readability.
05 | TRACE AND BUILD
TRACE A SCORE UPDATE
Predict the values of score and saved_score, then write a program that proves your prediction.
YOUR REQUIREMENTS
- Start score at 10.
- Copy its current numeric value into saved_score.
- Add 5 to score using score = score + 5.
- Print both names with labels.
- Explain why the saved value does not change.
Hint: where to begin
Evaluate the assignment’s right side using the current value. A numeric copy is not a live link to later reassignments.
TEST YOUR PROGRAM
| Test input or action | Expected result |
|---|---|
| Start 10, add 5 | Current score: 15; Saved score: 10 |
| Start 0, add 5 | Current score: 5; Saved score: 0 |
| Start 10, add 0 | Both values are 10. |
Reveal one possible solution and explanation
score = 10
saved_score = score
score = score + 5
print("Current score:", score)
print("Saved score:", saved_score)The update reads the earlier score, adds five, then associates score with fifteen. saved_score still refers to the earlier immutable numeric value ten. The assignment did not record a formula to recalculate later.
A different implementation can also be correct if it meets the requirements and tests. Compare meaning and behaviour, rather than only copying the source.
Extension: Add another update of seven after the first. Predict both final values before running again.
06 | APPLY INPUT
CALCULATE TRIP DISTANCE
Ask a traveller for a first name, a whole-number trip duration and a daily distance. Report the total planned distance.
YOUR REQUIREMENTS
- Use input() for the name and strip surrounding whitespace.
- Convert the day count using int().
- Convert daily kilometres using float().
- Multiply days by daily distance.
- Print a personalised result with kilometres as the unit.
Hint: where to begin
input returns text even when digits are typed. State that the first version assumes non-negative days and distance and valid numeric text.
TEST YOUR PROGRAM
| Test input or action | Expected result |
|---|---|
| Maya; 3; 12.5 | 37.5 km |
| Kai; 1; 0 | 0.0 km |
| Maya; three; 12.5 | ValueError: document the current input assumption. |
Reveal one possible solution and explanation
username = input("First name: ").strip()
days = int(input("Trip days (whole number, 0 or more): "))
daily_km = float(input("Daily distance in kilometres: "))
total_km = days * daily_km
print(f"{username}, your planned distance is {total_km:.1f} km.")Conversion lets multiplication operate on numbers rather than text. The unit belongs in the prompt and report; entering "12.5 km" instead of plain numeric text would fail float conversion. strip returns a cleaned name, which is used in the assignment.
A different implementation can also be correct if it meets the requirements and tests. Compare meaning and behaviour, rather than only copying the source.
Extension: Add a separate whole-number rest-day input. Calculate active days from the stated valid-input assumptions, then test a trip with one rest day.
07 | REPAIR INPUT
REPAIR TEXT ADDITION
A student asks for two numbers but receives the output 123 when entering 12 and 3. Diagnose the problem and correct it.
YOUR REQUIREMENTS
- Explain the original output before changing the source.
- Convert both responses to numbers.
- Allow fractional values in the corrected program.
- Print a labelled numeric sum.
SOURCE TO REPAIR
first = input("First number: ")
second = input("Second number: ")
print(first + second)Hint: where to begin
Two strings joined with + concatenate. Convert suitable responses using float before adding.
TEST YOUR PROGRAM
| Test input or action | Expected result |
|---|---|
| 12 and 3 | Sum: 15.0 |
| 2.5 and 0.5 | Sum: 3.0 |
| Blank numeric response | ValueError: empty text is not numeric zero. |
Reveal one possible solution and explanation
first = float(input("First number: "))
second = float(input("Second number: "))
print("Sum:", first + second)The original input calls returned "12" and "3". Their + operation joined them to "123". Converting both to float changes the operation to numeric addition. This does not make invalid text acceptable or add retry behaviour.
A different implementation can also be correct if it meets the requirements and tests. Compare meaning and behaviour, rather than only copying the source.
Extension: Create a separate whole-number version using int and explain what happens for response 2.5.
08 | REPAIR A FORMULA
FIND THE CORRECT MEAN
The expression first + second / 2 runs, but it does not normally calculate the mean of both numbers. Repair the formula and prove it with test cases.
YOUR REQUIREMENTS
- Store first and second as numeric values.
- Group their whole sum before dividing by 2.
- Print the mean with a label.
- Compare the original and repaired results for 8 and 12.
Hint: where to begin
Division groups more tightly than addition. Parentheses can force the sum to be calculated first.
TEST YOUR PROGRAM
| Test input or action | Expected result |
|---|---|
| 8 and 12 | Correct mean 10.0; original formula 14.0 |
| 0 and 10 | Correct mean 5.0 |
| 4 and 4 | Correct mean 4.0 |
Reveal one possible solution and explanation
first = 8
second = 12
mean = (first + second) / 2
print("Mean:", mean)
print("Original formula:", first + second / 2)The original halves only second, then adds first. The corrected formula sums both values before dividing the result by two. A logic error can execute without an exception while answering the wrong question.
A different implementation can also be correct if it meets the requirements and tests. Compare meaning and behaviour, rather than only copying the source.
Extension: Extend to three named values and calculate their mean. Use values 3, 6 and 9 to check for a result of 6.0.
09 | APPLY ARITHMETIC
GROUP COMPONENTS INTO KITS
A robotics club groups identical components into equal-size kits. Report complete kits and leftover components.
YOUR REQUIREMENTS
- Receive a non-negative whole-number component count.
- Receive a positive whole-number kit size.
- Use // for complete kits and % for leftovers.
- Label both results.
- Check that complete kits × kit size + leftovers reconstructs the input.
Hint: where to begin
Use int for both quantities. The kit size must be positive under the core version’s assumption. % is a remainder operation, not a percentage operation.
TEST YOUR PROGRAM
| Test input or action | Expected result |
|---|---|
| 17 and 5 | 3 kits; 2 left; reconstruction 17 |
| 20 and 5 | 4 kits; 0 left |
| 0 and 5 | 0 kits; 0 left |
| 17 and 0 | ZeroDivisionError: document the positive-size assumption. |
Reveal one possible solution and explanation
components = int(input("Components (whole number, 0 or more): "))
kit_size = int(input("Components per kit (whole number greater than 0): "))
complete_kits = components // kit_size
leftovers = components % kit_size
print("Complete kits:", complete_kits)
print("Leftover components:", leftovers)
print("Check total:", complete_kits * kit_size + leftovers)For non-negative counts and a positive capacity, floor division counts complete groups and modulo gives the leftover amount. The reconstruction verifies that neither components nor units have been lost. It does not decide whether an extra partly filled kit is required.
A different implementation can also be correct if it meets the requirements and tests. Compare meaning and behaviour, rather than only copying the source.
Extension: Add a true-division report for the ratio components / kit_size and explain why it differs from complete kits.
10 | STRETCH THE BASICS
MAKE A MEASUREMENT REPORT
Create a square-planning tool that calculates area and perimeter from a side length in centimetres.
YOUR REQUIREMENTS
- Read a non-negative numeric side length using float().
- Use ** 2 for square area.
- Use 4 * side for perimeter.
- Display area in square centimetres and perimeter in centimetres.
- Format both values to two decimal places.
Hint: where to begin
Area and perimeter have different units. ** means a power; ^ is not Python exponentiation. Formatting changes display rather than the stored value.
TEST YOUR PROGRAM
| Test input or action | Expected result |
|---|---|
| Side 4 | Area 16.00 square cm; perimeter 16.00 cm |
| Side 2.5 | Area 6.25 square cm; perimeter 10.00 cm |
| Side 0 | Both results are zero. |
Reveal one possible solution and explanation
side = float(input("Square side length in centimetres: "))
area = side ** 2
perimeter = 4 * side
print(f"Area: {area:.2f} square cm")
print(f"Perimeter: {perimeter:.2f} cm")The same numeric answer for side four does not mean the quantities are interchangeable: one measures surface and the other boundary length. A fractional test exposes the difference. Formatting to two places improves reporting, not arithmetic exactness.
A different implementation can also be correct if it meets the requirements and tests. Compare meaning and behaviour, rather than only copying the source.
Extension: Add a named price_per_square_cm value and estimate material cost from area. State that this is a beginner estimate rather than exact financial accounting.
11 | CAPSTONE
BUILD A PERSONALISED PRACTICE PLANNER
Build your own version of the Section 1 calculator project. Choose a theme such as coding, robotics or music practice.
YOUR REQUIREMENTS
- Greet a user by first name.
- Calculate completed practice from sessions, session minutes and extra minutes.
- Convert total minutes to hours.
- Calculate average minutes per positive completed-project count.
- Plan a separate future whole-hour block using a positive whole-minute session size.
- Report complete future sessions and leftover target minutes.
- Use comments, meaningful names and a named minutes-per-hour constant.
Hint: where to begin
Separate completed practice from the future block. Follow the lesson’s input assumptions; selection, loops and exception handling are not required yet.
TEST YOUR PROGRAM
| Test input or action | Expected result |
|---|---|
| Maya; 3; 25; 10; 2; 2; 25 | 85.0 minutes; 1.42 hours; 42.5 mean; 4 future sessions; 20 left |
| Kai; 0; 10; 0; 1; 0; 20 | Zero completed practice, zero target and zero leftover |
| Maya; 2; 12.5; 0; 1; 1; 20 | 25.0 minutes; 0.42 hours; 25.0 mean; 3 future sessions; 0 left |
Reveal one possible solution and explanation
# Personalised practice calculator
# Core version assumes valid numbers and positive divisors.
MINUTES_PER_HOUR = 60
print("Practice planner")
username = input("First name: ").strip()
sessions = int(input("Completed sessions (whole number, 0 or more): "))
minutes_per_session = float(input("Minutes per completed session: "))
extra_minutes = float(input("Extra practice minutes: "))
projects = int(input("Completed projects (whole number greater than 0): "))
target_hours = int(input("Future target hours (whole number, 0 or more): "))
planned_minutes = int(input("Future session minutes (whole number greater than 0): "))
# Completed practice and mean allocation per project
total_minutes = sessions * minutes_per_session + extra_minutes
total_hours = total_minutes / MINUTES_PER_HOUR
average_minutes = total_minutes / projects
# A separate future practice block
target_minutes = target_hours * MINUTES_PER_HOUR
complete_sessions = target_minutes // planned_minutes
leftover_minutes = target_minutes % planned_minutes
print()
print(f"Practice report for {username}")
print(f"Completed practice: {total_minutes:.1f} minutes")
print(f"Completed practice: {total_hours:.2f} hours")
print(f"Average practice per project: {average_minutes:.1f} minutes")
print(f"Future target block: {target_minutes} minutes")
print(f"Complete future sessions: {complete_sessions}")
print(f"Unused time in that block: {leftover_minutes} minutes")The full report combines input, conversion, variables, arithmetic and f-strings. The future target is a separate block rather than a subtraction from completed work. The mean describes allocation per project and does not prove that every project took the same time.
A different implementation can also be correct if it meets the requirements and tests. Compare meaning and behaviour, rather than only copying the source.
Extension: Add a minutes-to-seconds report, then rerun the known tests to check that your change has not altered earlier results.
12 | REFLECT AND EXTEND
TEST, IMPROVE AND HAND OVER
Improve one of your completed programs and let a partner use it without verbal instructions. Provide evidence that the improvement works.
YOUR REQUIREMENTS
- Write a short user guide with valid sample input and units.
- Record at least three expected and actual results.
- Include an exact-division or zero-quantity case where suitable.
- Document invalid text and zero-divisor limitations where relevant.
- Add one useful calculation and repeat the earlier tests.
- Explain one code design choice using because or therefore.
Hint: where to begin
A helpful prompt guides input but does not validate it. Compare your earlier results after a change; this is a regression check.
TEST YOUR PROGRAM
| Test input or action | Expected result |
|---|---|
| 3 sessions of 25 plus 10 extra | 85.0 minutes; 5100 seconds |
| 0 sessions and 0 extra | 0.0 minutes; 0 seconds |
| 2 sessions of 12.5, no extra | 25.0 minutes; 1500 seconds |
Reveal one possible solution and explanation
# A useful extension to the completed-practice calculation
MINUTES_PER_HOUR = 60
SECONDS_PER_MINUTE = 60
sessions = 3
minutes_per_session = 25.0
extra_minutes = 10.0
total_minutes = sessions * minutes_per_session + extra_minutes
total_seconds = total_minutes * SECONDS_PER_MINUTE
print(f"Completed minutes: {total_minutes:.1f}")
print(f"Completed seconds: {total_seconds:.0f}")The extension gives seconds = minutes × 60. Keeping the named conversion factor documents its meaning. A handover test also checks communication: a program that needs continuous coaching may have unclear prompts or units even when the arithmetic is correct.
A different implementation can also be correct if it meets the requirements and tests. Compare meaning and behaviour, rather than only copying the source.
Extension: List the next improvements you would make with comparisons, decisions and loops. Describe their purpose without using syntax you have not learned yet.
KEEP A SMALL TEST RECORD
For each test, write the input, predicted output, actual output and whether they match. If a mismatch occurs, identify whether it came from conversion, a formula, the chosen operator, units or displayed wording.
| Program | Input | Expected | Actual | Next action |
|---|---|---|---|---|
| Trip report | 3 days, 12.5 km/day | 37.5 km | Fill this in after running | Keep or correct |
| Grouping | 20 components, 5 per kit | 4 kits, 0 left | Fill this in after running | Keep or correct |
| Practice planner | Sample from challenge 11 | 85 minutes, 4 future sessions, 20 left | Fill this in after running | Keep or correct |
For a known limitation, state the observed exception and the assumption it breaks. Do not mark an error as a successful robust response just because the current version was expected to fail.
READY FOR THE NEXT SECTION?
You are ready to move on when you can save and run a file, explain text versus numbers, collect and convert suitable input, choose arithmetic operators and test a result you predicted.
If one skill is uncertain, revisit its lesson and change a worked example before repeating the challenge. The Section 1 workbook is coming soon.
Next: comparisons and Boolean logic Python course navigation