GRADE 8 · COMPUTING · UNIT 1 · LESSON 1.18

Computational thinking and programming

Translate conditions into Python

Read a little. Try the workbook. Check your answers. Choose one section below to get started.

Topic 1.18 · Translate conditions into Python10 fillable worksheet pagesRead at your own pace

LET’S TRACE, REASON AND TEST

Translate conditions into Python

Python comparisons use operators such as ==, !=, < and >=. An IF header ends with a colon and its body is indented. Assignment with = is different from an equality comparison.

Today’s two goals
  • Bridge from pseudocode to Python comparisons, lowercase if, a colon and an indented suite.
  • Explain my method and support it with a labelled trace, example or test record.
Original PaxaKids illustration for Translate conditions into Python. Use the supplied program and data models for precise workbook facts.
An original PaxaKids workbook scene. Use the supplied programs and data for precise workbook facts.

Work through an example

If count = 7, the expression count == 7 is true. A conditional print inside if count == 7: runs; replacing == with = is not a valid equality test in that header.

Try before your workbook

Which operator tests whether two values are different in Python, and what does 4 != 4 produce?

Explore the clues

Tap one card to find out more.

Understand the idea

Python comparisons use operators such as ==, !=, < and >=. An IF header ends with a colon and its body is indented. Assignment with = is different from an equality comparison.

Concept to practise: Translate conditions into Python.

Work through an example

If count = 7, the expression count == 7 is true. A conditional print inside if count == 7: runs; replacing == with = is not a valid equality test in that header.

Try before your workbook

Which operator tests whether two values are different in Python, and what does 4 != 4 produce?

Check my readiness thinking

Use !=. The comparison 4 != 4 produces False because the two values are equal.

Your original programs and learning models

These original PaxaKids program and data models support your workbook. Some examples deliberately contain faults to investigate. Follow their headings and preserve exact code case, punctuation and order. Traces and supplied records are not claims of physical testing.

Turn a decision into executable Python

A condition is an expression that can be evaluated as True or False. Selection chooses which statements to execute from that result.

Pseudocode explains the algorithm. Python requires its own exact syntax: lowercase if, a colon after the condition and an indented block. This lesson uses four spaces for each block level.

Choose the comparison that matches the rule

Comparisons test relationships between values. Python writes equality as == and not equal as !=. The operators and, or and not combine or reverse Boolean results; they are different from the comparison operators.
Choose the comparison that matches the rule — original model
OperatorMeaningExample result
>Greater than9 > 9 is False
Less than8 < 9 is True
>=Greater than or equal to9 >= 9 is True
<=Less than or equal to9 <= 9 is True
==Equal to9 == 9 is True
!=Not equal to8 != 9 is True

Keep assignment separate from equality

The first statement below stores the integer 9. The second compares the stored value with 9. The comparison does not change count. Use True or False for each comparison in the table.
Keep assignment separate from equality — original model
ExpressionYour result
count == 9{'clue': 'True or False', 'prompt': 'count equals 9', 'answers': ['True']}
count != 9{'clue': 'True or False', 'prompt': 'count differs from 9', 'answers': ['False']}
count > 9{'clue': 'True or False', 'prompt': 'count greater than 9', 'answers': ['False']}
count >= 9{'clue': 'True or False', 'prompt': 'count at least 9', 'answers': ['True']}
Assignment followed by comparisons
count = 9
count == 9
count != 9
count > 9
count >= 9

Translate the same single-branch algorithm

Input is integer text, such as 8, 9 or 10. int(input()) reads and converts it to an integer; this short program does not handle nonnumeric input. OUTPUT becomes print(). Python uses indentation instead of THEN and ENDIF.
Pseudocode
INPUT count
IF count >= 9 THEN
    OUTPUT "Ready"
ENDIF
OUTPUT "Checked"
Python 3
count = int(input())
if count >= 9:
    print("Ready")
print("Checked")

Trace the block and the boundary

Use the page 4 program. Entered input is not itself an output line. If count is below 9, the Ready line is skipped and Checked is printed. At 9 or above, Ready is printed first and Checked second.
Trace the block and the boundary — original model
Input countFirst output lineNumber of output lines
8{'clue': 'Exact text', 'prompt': 'First output for count 8', 'answers': ['Checked']}{'clue': 'Line count', 'prompt': 'Output lines for count 8', 'answers': ['1']}
9{'clue': 'Exact text', 'prompt': 'First output for count 9', 'answers': ['Ready']}{'clue': 'Line count', 'prompt': 'Output lines for count 9', 'answers': ['2']}
10{'clue': 'Exact text', 'prompt': 'First output for count 10', 'answers': ['Ready']}{'clue': 'Line count', 'prompt': 'Output lines for count 10', 'answers': ['2']}

Recall compound decisions before translating them

This original sensor-reading example revisits AND and OR in pseudocode. High means strictly greater than 40. Test the first condition first. If it succeeds, take its output and skip the remaining alternatives.
Three possible outcomes
INPUT firstReading
INPUT secondReading
IF firstReading > 40 AND secondReading > 40 THEN
    OUTPUT "Both high"
ELSEIF firstReading > 40 OR secondReading > 40 THEN
    OUTPUT "One high"
ELSE
    OUTPUT "Neither high"
ENDIF

Select input pairs for every outcome

Apply the page 6 rules. Boundary values are especially useful: a reading of exactly 40 is not greater than 40. Complete the output text for every pair.
Select input pairs for every outcome — original model
FirstSecondExact output
4142{'clue': 'Both high / One high / Neither high', 'prompt': 'Output for readings 41 and 42', 'answers': ['Both high']}
4140{'clue': 'Both high / One high / Neither high', 'prompt': 'Output for readings 41 and 40', 'answers': ['One high']}
4041{'clue': 'Both high / One high / Neither high', 'prompt': 'Output for readings 40 and 41', 'answers': ['One high']}
4040{'clue': 'Both high / One high / Neither high', 'prompt': 'Output for readings 40 and 40', 'answers': ['Neither high']}

Check syntax without changing the policy

All examples should implement: if count is at least 9, print Ready; then print Checked for every valid integer input. The editor may insert spaces when Tab is pressed. Use a consistent four-space indent and do not mix tabs and spaces.
A: compare and indent
count = int(input())
if count >= 9:
    print("Ready")
print("Checked")
B: different block
count = int(input())
if count >= 9:
    print("Ready")
    print("Checked")

Files for this activity

Use these original PaxaKids practice files with the matching workbook. Work on a local copy in the appropriate editor. Some examples deliberately contain faults to investigate; a downloaded file is not a completed practical test.

Paxa the Fox

Try one step with Paxa!

Trace code in the stated order and preserve exact spelling and case. Use fictional data. Label a prediction, paper trace, simulator run and physical-device test separately; an unperformed test stays Pending. Save personal responses before leaving.

Our Unit 1 learning path
  1. Lesson 1.1: Recall algorithms and representations
  2. Lesson 1.2: Purpose and conventions of pseudocode
  3. Lesson 1.3: Input, output and strings
  4. Lesson 1.4: Identifiers and assignment
  5. Lesson 1.5: Arithmetic and translation
  6. Lesson 1.6: Trace and review a sequence
  7. Lesson 1.7: Conditions and two-way flow
  8. Lesson 1.8: IF THEN and indentation
  9. Lesson 1.9: IF THEN ELSE and decision diagrams
  10. Lesson 1.10: Ordered ELSEIF and fallback ELSE
  11. Lesson 1.11: Match flowchart and pseudocode branches
  12. Lesson 1.12: AND, OR and NOT
  13. Lesson 1.13: Grouping, precedence and review
  14. Lesson 1.14: Why software searches
  15. Lesson 1.15: A successful linear search
  16. Lesson 1.16: An unsuccessful search and termination
  17. Lesson 1.17: Practise and communicate the search
  18. Lesson 1.18: Translate conditions into Python
  19. Lesson 1.19: One-branch IF programs
  20. Lesson 1.20: Two-way IF ELSE programs
  21. Lesson 1.21: Ordered ELIF choices
  22. Lesson 1.22: Ranges and independent decisions
  23. Lesson 1.23: Boolean operators in Python
  24. Lesson 1.24: Design and test recommendations
  25. Lesson 1.25: Trace, debug and reflect
  26. Lesson 1.26: Choose data types and recognise Boolean literals
  27. Lesson 1.27: Set and use Boolean flags
  28. Lesson 1.28: Explain and identify constants
  29. Lesson 1.29: Express constants in three algorithm forms
  30. Lesson 1.30: Use a fixed factor in a calculation
  31. Lesson 1.31: Cast to Boolean and validate an empty response
  32. Lesson 1.32: Recall calls and trace return values
  33. Lesson 1.33: Supply parameters and reuse library code
  34. Lesson 1.34: Choose and import libraries responsibly
  35. Lesson 1.35: Round with floor and ceiling
  36. Lesson 1.36: Use pi and investigate another mathematical feature
  37. Lesson 1.37: Generate random choices within bounds
  38. Lesson 1.38: Investigate random real values and review library use
  39. Lesson 1.39: Retrieve test tables and predict selection outcomes
  40. Lesson 1.40: Decompose everyday problems
  41. Lesson 1.41: Decompose programs and organise shared work
  42. Lesson 1.42: Develop through repeated build/test cycles
  43. Lesson 1.43: Predict and verify algorithm outcomes
  44. Lesson 1.44: Choose representative and boundary tests
  45. Lesson 1.45: Build, execute and review a test plan
  46. Lesson 1.46: Recall physical inputs and compare transmission media
  47. Lesson 1.47: Configure a radio group and agree a message scheme
  48. Lesson 1.48: Send and receive numbers and strings
  49. Lesson 1.49: Trace numeric message sequences
  50. Lesson 1.50: Transmit text and use received data in conditions
  51. Lesson 1.51: Diagnose and extend a message protocol
  52. Lesson 1.52: Review communication and evidence of testing
  53. Lesson 1.53: Project 1: Adventure story
  54. Lesson 1.54: Project 2: Fire, Water, Earth
  55. Lesson 1.55: Check your progress 1
For grown-ups: using this lesson

Your answers are checked in your browser. Open responses need grown-up review and are shown separately from the automatic score. Check your work, then use “Retry answers to practise” to revisit mistakes while keeping correct responses.

Read one explanation, discuss the model and try the readiness check before the workbook. Choose “Mark lesson finished” when ready. Optional account progress saves lesson position and completion across devices; save personal responses before leaving.

2. Fill in your workbook

Read the teaching and complete workbook instructions. Choose, write or draw; Answer list offers larger controls. Trace code precisely and distinguish predictions from actual tests. Review designs, explanations and drawings with a grown-up.

Translate conditions into Python10 student pages · original artwork

Opening your PDF…

Swipe sideways across the worksheet on a small screen, or use “Answer list” for larger controls.

TAKE YOUR PRACTICE OFFLINE

3. Download the student worksheet

All 10 original A4 student pages, ready for pencil-and-paper practice. Choose Review Answers to check your work on this webpage.

Student worksheet only · PDF · 8.0 MiB · No answer key included

Download worksheet PDF ↓

TRY FIRST, THEN CHECK TOGETHER

Download the student worksheet →

4. Answers & guidance

Finished your try? Open the guide and compare one worksheet at a time. Your own words may be different and still explain the right idea.

Shown on this webpage only. There is no answer-key download, and this guide is left out when printing the page.

Show answers for all 10 worksheets

Worksheet 1

  1. Question 1: What does a condition provide? a result that can be True or False
  2. Question 2: Which Python keyword starts a conditional statement? if

Worksheet 2

  1. Question 3: Write the comparison operator for at least. >=
  2. Question 4: Write the comparison operator for different from. !=

Worksheet 3

  1. Question 5: count equals 9 True
  2. Question 6: count differs from 9 False
  3. Question 7: count greater than 9 False
  4. Question 8: count at least 9 True

Worksheet 4

  1. Question 9: Which punctuation symbol ends the Python if header? :
  2. Question 10: How many leading spaces indent print("Ready") in this example? 4
  3. Question 11: Which statement is outside the conditional block? print("Checked")

Worksheet 5

  1. Question 12: First output for count 8 Checked
  2. Question 13: Output lines for count 8 1
  3. Question 14: First output for count 9 Ready
  4. Question 15: Output lines for count 9 2
  5. Question 16: First output for count 10 Ready
  6. Question 17: Output lines for count 10 2
  7. Question 18: Why is print("Checked") unindented? it belongs after the conditional block

Worksheet 6

  1. Question 19: Which Boolean operator requires both comparisons to be true? AND
  2. Question 20: After the Both high branch is selected, what happens? the later alternatives are skipped

Worksheet 7

  1. Question 21: Output for readings 41 and 42 Both high
  2. Question 22: Output for readings 41 and 40 One high
  3. Question 23: Output for readings 40 and 41 One high
  4. Question 24: Output for readings 40 and 40 Neither high
  5. Question 25: Which pair produces Neither high? 39 and 40

Worksheet 8

  1. Question 26: Which version follows the complete policy? A
  2. Question 27: What does version B print for input 8? no output lines
  3. Question 28: Which header is valid Python for this rule? if count >= 9:

Worksheet 9

  1. Question 29: Write pseudocode and Python for this rule: read an integer pack count; if it is at least 6, print Pack ready. After that decision, print Check complete for every valid integer input. Use one if, a colon and a four-space block. Test 5, 6 and 7. Record predicted output lines, then actual Python output if you run it, or mark execution Pending. Explain why the exact threshold 6 and the unindented final output matter. Require integer conversion, if packs >= 6:, four spaces before print("Pack ready"), unindented print("Check complete"). Pseudocode same rule using INPUT/IF THEN/ENDIF/OUTPUT. For 5 only Check complete; for 6 and 7 Pack ready then Check complete. Three predicted/observed cases or honest Pending. Explain inclusive boundary and final outside block. Accept equivalent meaningful variable names and correct syntax. No claim of learner execution without evidence. Grown-up review; personal evidence is required.

Worksheet 10

  1. Question 30: For the sensor pseudocode on page 6, choose your own input pair for each of Both high, One high and Neither high. Include a pair with one reading exactly 40. State the comparison results and why the selected output follows. Give a second pair that makes One high with the other reading high. Explain why a pair with both readings high prints only Both high. Review your work with a partner if available; otherwise label it an individual review. Record any correction and the evidence that supports it. All inputs supplied by learner must meet strict >40. Both high requires both above 40; One high exactly one above 40, covering both orientations; Neither high both <=40. At least one pair uses 40. Explain first-match chain skips later branch after true first condition even though OR would also be true. Identify actual individual/peer review honestly and explain a correction if any. No fabricated partner evidence and no numerical marks. Grown-up review; personal evidence is required.
Back to my workbook ↑

Curriculum & workbook reference

Computing for your homeschool day

Explore Translate conditions into Python with this free Grade 8 Computing lesson. Read one idea together, try the fillable workbook and return to review at your own pace. Download the same student worksheet PDF for pencil-and-paper practice.

Fit learning around your family’s day. There is no timer and no sign-up is needed to use the lesson. An optional account saves your lesson position and completion across devices. Workbook responses and drawings stay in this tab; save a copy of your responses before leaving.

Understand your results

Closed answers are checked in your browser. Drawings and written explanations need grown-up review and are shown separately from the automatic score. Check your work, then use “Retry answers to practise” to revisit mistakes while keeping correct responses.

Choose Review Answers after trying the activity. The guide stays on the webpage; the worksheet download contains only the student pages.

For programme background, visit the Cambridge Lower Secondary Computing overview. PaxaKids provides independent original companion practice.

Book page references identify the related teaching topic. File-management and responsible-data preparation are original PaxaKids material; orientation or contents pages are not presented as teaching citations for those skills. The explanations, characters, programs and exercises here are original PaxaKids companion practice. Practical tasks require the appropriate editor and, where applicable, suitable equipment. A design or paper trace is not a verified hardware result. Only completed, reviewed lessons are listed.

Explore the Cambridge Lower Secondary Computing curriculum for programme background. PaxaKids is an independent learning resource.