GRADE 8 · COMPUTING · UNIT 1 · LESSON 1.19

Computational thinking and programming

One-branch IF programs

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

Topic 1.19 · One-branch IF programs12 fillable worksheet pagesRead at your own pace

LET’S TRACE, REASON AND TEST

One-branch IF programs

A one-branch Python IF can perform an action when its condition is true and do nothing in its body otherwise. After the block, execution continues with the next instruction.

Today’s two goals
  • Predict and modify a simple true-branch program; distinguish conditional actions from the final output that always runs.
  • Explain my method and support it with a labelled trace, example or test record.
Original PaxaKids illustration for One-branch IF programs. 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

With limit = 9 and amount = 6, if amount > limit: does not run its indented warning. A print after the block still runs.

Try before your workbook

If amount and limit are both 9, does amount > limit run the warning? Explain.

Explore the clues

Tap one card to find out more.

Understand the idea

A one-branch Python IF can perform an action when its condition is true and do nothing in its body otherwise. After the block, execution continues with the next instruction.

Concept to practise: One-branch IF programs.

Work through an example

With limit = 9 and amount = 6, if amount > limit: does not run its indented warning. A print after the block still runs.

Try before your workbook

If amount and limit are both 9, does amount > limit run the warning? Explain.

Check my readiness thinking

No. Equality does not satisfy >. Use a test at the boundary to check whether the intended policy should include equality.

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.

One branch can change what happens

At a fictional book fair, a Python program can issue an extra message or adjust a credit total only when a condition is true. A single if does not require an else.

You will predict, run where possible, investigate, modify and make programs. All data here are invented. Distinguish your predictions from observed output.

Predict the original bonus-badge program

This program is supplied in original module C04. Enter one integer token count. The badge message is conditional; the final line is outside the block.
Original Paxa c04_bonus_badge.py
tokens = int(input())
if tokens >= 12:
    print("Bonus badge")
print("Visit recorded")

Trace exact text and case sensitivity

The following original joke program reads an unprompted input line. It prints the two joke lines only for exact lowercase yes. The final line prints after either outcome. Entered text is not printed automatically.
Trace exact text and case sensitivity — original model
Entered textNumber of printed lines
yes{'clue': 'Line count', 'prompt': 'Printed line count for yes', 'answers': ['3']}
no{'clue': 'Line count', 'prompt': 'Printed line count for no', 'answers': ['1']}
YES{'clue': 'Line count', 'prompt': 'Printed line count for YES', 'answers': ['1']}
Original Paxa message program
choice = input()
if choice == "yes":
    print("Why did the keyboard join the band?")
    print("It had plenty of keys.")
print("Choice recorded")

Investigate and modify the text decision

Read the page 3 program. The comparison is choice == "yes"; == is the comparison operator. Both indented print statements belong to the same block.

For the modified version, display the prompt Enter Y for the joke or N to skip, accept exactly uppercase Y and keep Choice recorded as the final message.

Prepare a new riddle program

Use this complete original brief: print Which three-letter word names a drawing of places? Read answer as text. Print Correct map answer only if answer is exactly map. Finally print Riddle finished after either outcome.

Use one if. A capital letter or a trailing space changes the exact string. Normalising text is a separate design choice, not a feature of this brief.
Prepare a new riddle program — original model
Answer enteredConditional message appears?
map{'clue': 'Yes or No', 'prompt': 'Conditional riddle message for map', 'answers': ['Yes']}
Map{'clue': 'Yes or No', 'prompt': 'Conditional riddle message for Map', 'answers': ['No']}
globe{'clue': 'Yes or No', 'prompt': 'Conditional riddle message for globe', 'answers': ['No']}

Read a conditional calculation

Fictional fair credits are used for arithmetic practice. The input domain is a nonnegative decimal total followed by a nonnegative integer item count, each on its own line. At least 8 items earns 20% off: multiply by 0.8. The final output always displays the resulting total if execution reaches it.
Original Paxa quantity offer
total = float(input())
items = int(input())
if items >= 8:
    total = total * 0.8
print(f"Total credits: {total:.2f}")

Predict original totals at and around the boundary

Use the page 6 program. Enter only the numeric total shown after Total credits: in the output, including two decimal places. These examples have exact expected displayed values.
Predict original totals at and around the boundary — original model
Total enteredItems enteredDisplayed total
32.57{'clue': 'Two decimal places', 'prompt': 'Displayed total for 32.5 credits and 7 items', 'answers': ['32.50']}
32.58{'clue': 'Two decimal places', 'prompt': 'Displayed total for 32.5 credits and 8 items', 'answers': ['26.00']}
32.59{'clue': 'Two decimal places', 'prompt': 'Displayed total for 32.5 credits and 9 items', 'answers': ['26.00']}
12.58{'clue': 'Two decimal places', 'prompt': 'Displayed total for 12.5 credits and 8 items', 'answers': ['10.00']}

Modify the condition and keep the calculation

Treat these as separate versions. Version A changes eligibility to at least 5 items. Version B changes eligibility to an original total of at least 30 credits, regardless of item count. Keep the 20% reduction and the unindented final print.

Plan a code-based offer

This original version accepts the exact text READ. Correct code reduces the total by 20% and prints Code accepted. The final total prints for either outcome. Input is a valid nonnegative decimal total, then the code, on separate lines.
Original Paxa code offer
total = float(input())
code = input()
if code == "READ":
    total = total * 0.8
    print("Code accepted")
print(f"Total credits: {total:.2f}")

Keep predictions, execution and corrections distinct

Resources include complete original programs, test records and creation scaffolds. Predict first, run in Python 3 if available, compare exact lines and retest corrections.

Test accepted, different and differently capitalised text. Test below, equal and above numeric thresholds. Vary total and code for the code offer. Without Python execution, trace manually and mark Run Pending.
Keep predictions, execution and corrections distinct — original model
RecordEvidence to keep
PlanCondition, conditional statements and outside statements.
PredictInput and exact output lines before running.
RunActual output or clearly marked Pending.
InvestigateWhich comparison was true and which lines executed.
Modify / makeSaved source or legible full code, with version name.
ReflectError if any, correction, retest and a next working habit.

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.

One-branch IF programs12 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 12 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.3 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 12 worksheets

Worksheet 1

  1. Question 1: When does an indented single-if block execute? when its condition is True
  2. Question 2: Does a single if require an else? no

Worksheet 2

  1. Question 3: What prints for input 11? Visit recorded only
  2. Question 4: What prints for input 12? Bonus badge then Visit recorded
  3. Question 5: How many output lines appear for input 13? 2

Worksheet 3

  1. Question 6: Printed line count for yes 3
  2. Question 7: Printed line count for no 1
  3. Question 8: Printed line count for YES 1

Worksheet 4

  1. Question 9: Which line is outside the if block? print("Choice recorded")
  2. Question 10: Which modified input line supplies the requested prompt? choice = input("Enter Y for the joke or N to skip: ")
  3. Question 11: Which modified condition accepts exactly uppercase Y? if choice == "Y":
  4. Question 12: What does lowercase y do in this exact-Y version? skip the joke and print Choice recorded

Worksheet 5

  1. Question 13: Conditional riddle message for map Yes
  2. Question 14: Conditional riddle message for Map No
  3. Question 15: Conditional riddle message for globe No
  4. Question 16: Write the comparison operator needed between answer and "map". ==

Worksheet 6

  1. Question 17: What percentage of the original total remains after multiplying by 0.8? 80
  2. Question 18: What percentage reduction does that represent? 20
  3. Question 19: Which statement is conditional? total = total * 0.8

Worksheet 7

  1. Question 20: Displayed total for 32.5 credits and 7 items 32.50
  2. Question 21: Displayed total for 32.5 credits and 8 items 26.00
  3. Question 22: Displayed total for 32.5 credits and 9 items 26.00
  4. Question 23: Displayed total for 12.5 credits and 8 items 10.00
  5. Question 24: Why must the 8-item case be tested? it is the exact inclusive threshold

Worksheet 8

  1. Question 25: Which header implements version A? if items >= 5:
  2. Question 26: Which header implements version B? if total >= 30:
  3. Question 27: For version A, what total prints from 20 credits and exactly 5 items? 16.00 / 16
  4. Question 28: For version B, what total prints from exactly 30 credits? 24.00 / 24
  5. Question 29: Why should the final print remain outside the if? both adjusted and unchanged totals must be displayed

Worksheet 9

  1. Question 30: With 25 credits and code READ, which output is correct? Code accepted then Total credits: 20.00
  2. Question 31: With 25 credits and code read, which output is correct? Total credits: 25.00 only

Worksheet 10

  1. Question 32: Which claim is justified without running the program? a labelled prediction from a manual trace

Worksheet 11

  1. Question 33: Save or write two complete programs. First adapt the page 3 message program: prompt for Y or N, accept exactly Y, show your own two-line joke or friendly message only then, and keep Choice recorded outside the block. Second implement the complete riddle brief on page 5. For each, mark its condition, comparison operator, conditional lines and outside lines. Test accepted, different and differently capitalised input. Record predictions, actual output or Pending, a correction if needed and one improvement to your working method. Cite saved code and test records if using files. Two complete programs or referenced actual files. Modified text input includes Y/N prompt, exact choice == "Y", two original conditional print lines and unconditional final Choice recorded. Riddle prints supplied question, reads answer, tests == "map", conditionally prints Correct map answer and finally Riddle finished. Tests include Y/N/y and map/globe/Map or equivalent cases that exercise specified distinctions. Annotate condition/operator/block/outside. Evidence must distinguish predictions, actual execution and Pending. Reflect on actual correction or explain no correction needed; identify next habit. No fabricated peer review. Grown-up review; personal evidence is required.

Worksheet 12

  1. Question 34: Create your own complete program from the page 9 policy: read a nonnegative decimal total and a code; only exact READ gives 20% off and prints Code accepted; print Total credits: followed by the resulting amount to two decimal places for either outcome. Plan the conditional and outside lines before coding. Test at least two different totals, the accepted code, an incorrect code and different capitalisation. Record predicted and actual output or Pending. Explain the multiplier, a correction or successful comparison, and how you will improve the next program. Cite saved code and test records. Full independently created code or saved file, float input total, string input code, if code == "READ":, multiply by 0.8 and print Code accepted inside four-space block, final formatted total outside. Normal domain nonnegative decimal input; no unstated invalid-input handling. Tests cover READ, wrong code, read and at least two totals; e.g. 25/READ -> accepted +20.00, 25/read ->25.00, 12.5/READ ->accepted +10.00, 12.5/WRONG ->12.50. Explain 80% remains so 20% off, predictions before actual run and honest Pending if not run. Record correction/retest or evidence no correction needed, next working habit. Floating display rounding not altered eligibility. No numeric marks. Grown-up review; personal evidence is required.
Back to my workbook ↑

Curriculum & workbook reference

Computing for your homeschool day

Explore One-branch IF programs 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.