GRADE 8 · COMPUTING · UNIT 1 · LESSON 1.22

Computational thinking and programming

Ranges and independent decisions

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

Topic 1.22 · Ranges and independent decisions16 fillable worksheet pagesRead at your own pace

LET’S TRACE, REASON AND TEST

Ranges and independent decisions

A chained choice and separate IF statements have different behaviour. A range condition combines a lower and an upper bound. Specify whether each bound includes equality.

Today’s two goals
  • Classify numeric directions or positions and distinguish mutually exclusive options from simultaneous edge alerts.
  • Explain my method and support it with a labelled trace, example or test record.
Original PaxaKids illustration for Ranges and independent decisions. 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

For x = 6, both independent conditions x > 2 and x < 9 are true, so both bodies can run. An IF/ELIF chain would select at most one of those bodies.

Try before your workbook

Does the range x >= 2 AND x < 6 include 6? Which endpoint is included?

Explore the clues

Tap one card to find out more.

Understand the idea

A chained choice and separate IF statements have different behaviour. A range condition combines a lower and an upper bound. Specify whether each bound includes equality.

Concept to practise: Ranges and independent decisions.

Work through an example

For x = 6, both independent conditions x > 2 and x < 9 are true, so both bodies can run. An IF/ELIF chain would select at most one of those bodies.

Try before your workbook

Does the range x >= 2 AND x < 6 include 6? Which endpoint is included?

Check my readiness thinking

It excludes 6 and includes 2. Testing both endpoints helps distinguish an intended range from an off-by-one error.

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.

Use directions, ranges and map positions

A navigation program can select one direction from a bearing. A game can select one movement command but report two edge alerts at a corner.

You will decide when one ordered chain is suitable and when two separate decisions are needed. Every numerical rule and valid input range is stated so boundaries can be tested accurately.

Read bearings clockwise from north

Bearings here are whole numbers from 0 to 359 degrees. North is at 0, East at 90, South at 180 and West at 270. The diagonal labels show the intermediate directions between these four.
Read bearings clockwise from north — original labelled workbook model. The following text version gives its labels and values.
Read bearings clockwise from north · original PaxaKids model.
Read this model’s labels and values

Classify a bearing into four direction sectors

For valid integer bearings 0–359, this ascending-threshold chain selects North for 0–44 and 315–359, East for 45–134, South for 135–224 and West for 225–314. A later test is reached only after the earlier ones are false.
Original Paxa four-direction classifier
bearing = int(input())
if bearing < 45:
    print("North")
elif bearing < 135:
    print("East")
elif bearing < 225:
    print("South")
elif bearing < 315:
    print("West")
else:
    print("North")

Test exact boundaries and the north wraparound

Use page 3. Fill the exact direction name for each bearing. The paired columns keep the complete ten-case test set together.
Test exact boundaries and the north wraparound — original model
BearingDirectionBearingDirection
0{'clue': 'Exact text', 'prompt': 'Direction for 0', 'answers': ['North']}224{'clue': 'Exact text', 'prompt': 'Direction for 224', 'answers': ['South']}
44{'clue': 'Exact text', 'prompt': 'Direction for 44', 'answers': ['North']}225{'clue': 'Exact text', 'prompt': 'Direction for 225', 'answers': ['West']}
45{'clue': 'Exact text', 'prompt': 'Direction for 45', 'answers': ['East']}314{'clue': 'Exact text', 'prompt': 'Direction for 314', 'answers': ['West']}
134{'clue': 'Exact text', 'prompt': 'Direction for 134', 'answers': ['East']}315{'clue': 'Exact text', 'prompt': 'Direction for 315', 'answers': ['North']}
135{'clue': 'Exact text', 'prompt': 'Direction for 135', 'answers': ['South']}359{'clue': 'Exact text', 'prompt': 'Direction for 359', 'answers': ['North']}

Specify an eight-direction version before coding

The nearest of eight directions has boundaries halfway between the labelled directions, such as 22.5 degrees between North and North-east. For integer inputs, the following complete policy avoids fractional inputs and leaves no gaps. North wraps around the end of the range.
Specify an eight-direction version before coding — original model
Valid integer bearingOutput
0–22 and 338–359North
23–67North-east
68–112East
113–157South-east
158–202South
203–247South-west
248–292West
293–337North-west

Specify nearest quarter-hour output

Read a whole number of minutes past the hour, from 0 to 59. Choose the nearest quarter-hour label using this complete policy. The label On the hour may mean the start of this hour or the next one; no hour number is requested.
Specify nearest quarter-hour output — original model
Minutes pastNearest label
0–7On the hour
8–22Quarter past
23–37Half past
38–52Quarter to
53–59On the hour

Read one movement command per run

This independent original program resets to x = 10, y = 15 each run. Accept exact uppercase U, D, R or L. Up increases y, down decreases y, right increases x and left decreases x. Other text prints a warning and leaves both coordinates unchanged.
Original Paxa movement program
x = 10
y = 15
command = input()
if command == "U":
    y = y + 1
elif command == "D":
    y = y - 1
elif command == "R":
    x = x + 1
elif command == "L":
    x = x - 1
else:
    print("Unknown command")
print("x:", x)
print("y:", y)

Trace separate runs, including invalid text

Begin again at (10, 15) for every row; do not carry a previous result into the next row. Write the resulting numeric x and y. Unknown commands leave the start unchanged and also print Unknown command.
Trace separate runs, including invalid text — original model
CommandResult xResult y
U{'clue': 'Integer', 'prompt': 'x after U', 'answers': ['10']}{'clue': 'Integer', 'prompt': 'y after U', 'answers': ['16']}
D{'clue': 'Integer', 'prompt': 'x after D', 'answers': ['10']}{'clue': 'Integer', 'prompt': 'y after D', 'answers': ['14']}
L{'clue': 'Integer', 'prompt': 'x after L', 'answers': ['9']}{'clue': 'Integer', 'prompt': 'y after L', 'answers': ['15']}
R{'clue': 'Integer', 'prompt': 'x after R', 'answers': ['11']}{'clue': 'Integer', 'prompt': 'y after R', 'answers': ['15']}
u{'clue': 'Integer', 'prompt': 'x after u', 'answers': ['10']}{'clue': 'Integer', 'prompt': 'y after u', 'answers': ['15']}
jump{'clue': 'Integer', 'prompt': 'x after jump', 'answers': ['10']}{'clue': 'Integer', 'prompt': 'y after jump', 'answers': ['15']}

Modify only the vertical step size

Create a separate version where U adds 4 to y and D subtracts 4. Keep left/right changes at 1 and keep the same starting coordinates. The displayed excerpt replaces only the first two action branches; the rest of the page 7 chain stays in place.
Original Paxa vertical-step modification excerpt
if command == "U":
    y = y + 4
elif command == "D":
    y = y - 4

Read the original C04 map and alert bands

This original map uses integer x from 0 to 80 and y from 0 to 40. Near an edge means at most 4 units from it, including exactly 4. Each horizontal and vertical test is independent, so two alerts can apply at a corner.
Read the original C04 map and alert bands — original labelled workbook model. The following text version gives its labels and values.
Read the original C04 map and alert bands · original PaxaKids model.
Read this model’s labels and values

Read independent horizontal and vertical decisions

This is the complete original C04 program. The outside-map check guards the remaining code. Within the map, the horizontal chain and vertical chain are separate. The final interior test is true only when no edge band applies.
Original Paxa c04_map_edges.py
x = int(input())
y = int(input())
if x < 0 or x > 80 or y < 0 or y > 40:
    print("Outside map")
else:
    if x <= 4:
        print("West edge")
    elif x >= 76:
        print("East edge")
    if y <= 4:
        print("South edge")
    elif y >= 36:
        print("North edge")
    if x > 4 and x < 76 and y > 4 and y < 36:
        print("Interior")

Predict edge, corner, interior and outside results

Use page 11. Write the number of printed alert/result lines and the first exact line. Horizontal alerts print before vertical alerts. Interior and Outside map are each one result line.
Predict edge, corner, interior and outside results — original model
Position (x, y)First printed lineLine count
(3, 38){'clue': 'Exact text', 'prompt': 'First map output at (3, 38)', 'answers': ['West edge']}{'clue': 'Integer', 'prompt': 'Map output line count at (3, 38)', 'answers': ['2']}
(77, 2){'clue': 'Exact text', 'prompt': 'First map output at (77, 2)', 'answers': ['East edge']}{'clue': 'Integer', 'prompt': 'Map output line count at (77, 2)', 'answers': ['2']}
(40, 20){'clue': 'Exact text', 'prompt': 'First map output at (40, 20)', 'answers': ['Interior']}{'clue': 'Integer', 'prompt': 'Map output line count at (40, 20)', 'answers': ['1']}
(-1, 20){'clue': 'Exact text', 'prompt': 'First map output at (-1, 20)', 'answers': ['Outside map']}{'clue': 'Integer', 'prompt': 'Map output line count at (-1, 20)', 'answers': ['1']}

Find the alert hidden by a single chain

The following intentionally flawed version accepts valid in-map inputs but combines every edge into one chain. Compare it with C04 before deciding whether it satisfies a two-alert corner requirement.
Intentional single-chain logic error
x = int(input())
y = int(input())
if x <= 4:
    print("West edge")
elif x >= 76:
    print("East edge")
elif y <= 4:
    print("South edge")
elif y >= 36:
    print("North edge")
else:
    print("Interior")

Plan, test and reflect on independence

Keep full source, test inputs, predictions and actual output or Pending for each created version. Test range boundaries, valid commands, wrong case, an interior point, a corner and outside-map input.

For your reflection, choose Worked independently, Used prompts or Needed guided support, then cite actual examples. Compare with an earlier programming task and identify one next step. These are evidence-based descriptions, not numeric ratings.

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.

Ranges and independent decisions16 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 16 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.4 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 16 worksheets

Worksheet 1

  1. Question 1: Which requirement may need two messages from one position? warn near both edges at a map corner
  2. Question 2: What should a numeric range specification make clear? which boundary values belong to each result

Worksheet 2

This page introduces the activity. There are no marked responses on this sheet.

Worksheet 3

  1. Question 3: How many elif headers are in this program? 3
  2. Question 4: What is the final else result for valid input? North
  3. Question 5: Why does bearing 90 reach the second test? 90 is not below 45

Worksheet 4

  1. Question 6: Direction for 0 North
  2. Question 7: Direction for 224 South
  3. Question 8: Direction for 44 North
  4. Question 9: Direction for 225 West
  5. Question 10: Direction for 45 East
  6. Question 11: Direction for 314 West
  7. Question 12: Direction for 134 East
  8. Question 13: Direction for 315 North
  9. Question 14: Direction for 135 South
  10. Question 15: Direction for 359 North

Worksheet 5

This page introduces the activity. There are no marked responses on this sheet.

Worksheet 6

  1. Question 16: What label is selected for 7 minutes? On the hour
  2. Question 17: What label is selected for 8 minutes? Quarter past

Worksheet 7

This page introduces the activity. There are no marked responses on this sheet.

Worksheet 8

  1. Question 18: x after U 10
  2. Question 19: y after U 16
  3. Question 20: x after D 10
  4. Question 21: y after D 14
  5. Question 22: x after L 9
  6. Question 23: y after L 15
  7. Question 24: x after R 11
  8. Question 25: y after R 15
  9. Question 26: x after u 10
  10. Question 27: y after u 15
  11. Question 28: x after jump 10
  12. Question 29: y after jump 15

Worksheet 9

  1. Question 30: In a fresh modified run, what y results from U? 19
  2. Question 31: In a fresh modified run, what y results from D? 11
  3. Question 32: In a fresh modified run, what x results from U? 10

Worksheet 10

This page introduces the activity. There are no marked responses on this sheet.

Worksheet 11

This page introduces the activity. There are no marked responses on this sheet.

Worksheet 12

  1. Question 33: First map output at (3, 38) West edge
  2. Question 34: Map output line count at (3, 38) 2
  3. Question 35: First map output at (77, 2) East edge
  4. Question 36: Map output line count at (77, 2) 2
  5. Question 37: First map output at (40, 20) Interior
  6. Question 38: Map output line count at (40, 20) 1
  7. Question 39: First map output at (-1, 20) Outside map
  8. Question 40: Map output line count at (-1, 20) 1
  9. Question 41: At x = 4, is the West edge test true? yes

Worksheet 13

  1. Question 42: At (3, 38), what does this wrong version print? West edge only
  2. Question 43: Which repair restores both axis alerts? start a separate if for the vertical edge tests

Worksheet 14

  1. Question 44: Which input best exposes a missing second edge alert? a corner-band point such as (3, 38)
  2. Question 45: What should support reflection record? the actual help used and evidence of work

Worksheet 15

  1. Question 46: Create separate eight-direction and nearest-quarter-hour programs from the complete policies on pages 5 and 6. State the valid input domains, use ordered conditions and give a defined result for every valid input. For the compass version, test all eight direction centres plus 22, 23 and 359. For time, test 7, 8, 22, 23, 52 and 53. Record exact predicted and actual output or Pending. Explain a boundary and the north/hour wraparound. Cite full saved programs and test records, or write and attach complete code. Eight-direction integer domain 0–359: <23 N,<68 NE,<113 E,<158 SE,<203 S,<248 SW,<293 W,<338 NW,else N, using stated full direction text. Test centres 0/45/90/135/180/225/270/315 plus22 N,23 NE,359 N. Clock integer domain 0–59: <8 On the hour,<23 Quarter past,<38 Half past,<53 Quarter to,else On the hour. Time cases: 7 gives On the hour; 8 and 22 give Quarter past; 23 gives Half past; 52 gives Quarter to; 53 gives On the hour. No gaps/overlaps in selected outcomes; complete code/file evidence, input domains explicit, exact predictions/actual or Pending, correction/retest if any. Accept equivalent correct ordered lower-bound chain. No numeric marks. Grown-up review; personal evidence is required.

Worksheet 16

  1. Question 47: Save a complete movement version with vertical steps of 4 and horizontal steps of 1 from (10, 15). Test U, D, L, R and an invalid command in fresh runs. Then implement or enter the complete C04 edge program and test (4, 36), (5, 35), (76, 4) and an outside point. Show why corner cases need separate horizontal and vertical decisions. Keep predicted and actual outputs or Pending and any correction/retest. Cite complete source and records. Finally use the page 14 reflection labels, describe help actually used and compare your independence with a previous task. Modified movement U=(10,19),D=(10,11),L=(9,15),R=(11,15); invalid unchanged with warning, both coordinate outputs after chain. Map (4,36) West then North; (5,35) Interior; (76,4) East then South; outside point Outside map only. Separate axis if blocks retain both warnings, exact inclusive boundaries and guard. Complete source and prediction/actual/Pending records. Reflection uses nonnumeric independence description, truthful actual help, comparison with prior task and concrete next step. No fabricated GUI, physical movement or partner activity. Grown-up review; personal evidence is required.
Back to my workbook ↑

Curriculum & workbook reference

Computing for your homeschool day

Explore Ranges and independent decisions 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.