GRADE 7 · COMPUTING · UNIT 1 · LESSON 1.7

Block it out: Moving from blocks to text

Casting

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

8 fillable worksheet pagesRead at your own pace

LET’S TRACE, REASON AND TEST

Casting

Casting converts a suitable value to another type. Convert input with int for a whole-number calculation or float for decimal input. Text repetition and numeric multiplication behave differently. A conversion can fail when the text is not a valid representation of the requested number.

Today’s two goals
  • Explain why input() returns text and why arithmetic may require a conversion.
  • Use int() or float() appropriately when collecting numeric input.
Original PaxaKids illustration for Casting. Precise program text and data are supplied in the workbook models.
An original PaxaKids workbook scene. Use the supplied programs and data for precise workbook facts.

Explore the clues

Tap one card to find out more.

Understand the idea

Casting converts a suitable value to another type. Convert input with int for a whole-number calculation or float for decimal input. Text repetition and numeric multiplication behave differently. A conversion can fail when the text is not a valid representation of the requested number.

Concept to practise: Casting.

Work through an example

If raw is the string "6", raw * 3 repeats it as "666". int(raw) * 3 calculates 18. For a price such as "7.5", float(raw) is appropriate; int("7.5") does not accept that decimal string.

Try before your workbook

A program needs to subtract a cost of 2.5 from a budget of 10 entered as text. Which conversion suits the cost, and what numeric result should follow?

Check my readiness thinking

Use float for the decimal cost, and convert the budget to a suitable number too. The calculation 10 - 2.5 gives 7.5; joining or repeating strings would not calculate the balance.

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.

Convert text for a calculation

Our goal: choose int or float for numeric input, explain string repetition, and test numeric programs.

Plain input returns text. Casting converts a value to another type when the conversion is valid. Use int for a whole-number input such as "6". Use float when a fractional value such as "2.5" is allowed.

Repeating text or multiplying numbers?

PROGRAM A
value = input("Value: ")
print(value * 3)
PROGRAM B
value = int(input("Value: "))
print(value * 3)

Repair a meal-balance program

FAULTY ORIGINAL STARTER
budget = input("Budget: ")
cost = input("Meal cost: ")
left = budget - cost
print("Left:", left)

Translate a simple game model

An original rabbit game awards nine points for each whole year entered. Its block-style plan is: ask for the rabbit’s age; store the answer; multiply the age by 9; display the game points. This is a programming model, not a biological rule about rabbit and human ages.

Calculate a square area

For a square, area = side × side. Use a positive whole-number side length in metres for this activity. Collect it with int(input(...)), calculate using the Python multiplication operator *, and display the area with square-metre units.

Calculate an average speed

Average speed = total distance ÷ total time. This program uses positive whole-number distances in metres and times in seconds. Convert both inputs with int. Use / for division; Python displays a float result. Choose a time greater than zero. This version does not validate invalid inputs.
Paxa the Fox

Try one step with Paxa!

Trace code carefully and preserve exact spelling, case and order. Use invented practice data. Save personal responses before leaving.

Our Unit 1 learning path
  1. Lesson 1.1: Comparing Scratch and Python
  2. Lesson 1.2: Using Python
  3. Lesson 1.3: Using Python IDLE in Script mode
  4. Lesson 1.4: Variables
  5. Lesson 1.5: Adding more information to a program
  6. Lesson 1.6: Data types – string, integer and real
  7. Lesson 1.7: Casting
  8. Lesson 1.8: Flowcharts and algorithms
  9. Lesson 1.9: BIDMAS in Python
  10. Lesson 1.10: Error detection and correction
  11. Lesson 1.11: Making choices IF THEN ELSE in flowcharts
  12. Lesson 1.12: Sub-routines
  13. Lesson 1.13: Random questions and a star number
  14. Lesson 1.14: Final project
  15. Lesson 1.15: Evaluation
  16. Lesson 1.16: What can you do?
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 the 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.

Casting8 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 8 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 8 worksheets

Worksheet 1

  1. Question 1: What type does plain input return? string
  2. Question 2: What does casting do? converts a value to another type
  3. Question 3: Which conversion fits a whole-number count typed as text? int

Worksheet 2

  1. Question 4: What does Program A display? 666
  2. Question 5: What does Program B display? 18
  3. Question 6: Why is Program A different? multiplying a string by 3 repeats its text

Worksheet 3

  1. Question 7: Which input line accepts a decimal budget as a number? budget = float(input("Budget: "))
  2. Question 8: Which responses need numeric conversion? both budget and cost
  3. Question 9: For a numeric budget 20 and cost 7.5, what amount is left? 12.5

Worksheet 4

  1. Question 10: What points should the game display for age 4? 36
  2. Question 11: Which Python line collects the age as a whole number? age = int(input("Rabbit age: "))
  3. Question 12: What does the factor 9 mean in this activity? the rule of this invented points game

Worksheet 5

  1. Question 13: What area should be displayed for side 5 metres? 25
  2. Question 14: Which assignment calculates the square area? area = side * side
  3. Question 15: Which input suits this whole-number version? 5

Worksheet 6

  1. Question 16: What Python result is produced by 120 metres divided by 8 seconds? 15.0
  2. Question 17: What Python result is produced by 90 metres divided by 4 seconds? 22.5
  3. Question 18: Which time is suitable for this calculation? a positive time greater than zero

Worksheet 7

  1. Question 19: Repair the page C meal program using decimal-capable inputs. Also write the page D rabbit-points program using a whole-number age. Record both programs and test meal pairs (20,7.5) and (15,9.5), plus game ages 2 and 4. Compare predicted and actual output and explain your conversions. Meal repair: convert budget and cost with float(input(...)), subtract cost from budget and print a clear label/value. Tests give Left: 12.5 and Left: 5.5, with spaces after labels. Rabbit game: age=int(input(...)); points=age*9; print a clear label and points. Ages2 and 4 give 18 and 36. Accept other valid variable names, matching single/double quotes and equivalent label wording. Require complete numeric conversions before arithmetic, honest run/trace evidence and an explanation of int versus float. The game factor is an invented model, not biology. Grown-up review; personal evidence is required.

Worksheet 8

  1. Question 20: Write and test a square-area program for sides 5 and 8 metres, and an average-speed program for (120 m, 8 s) and (90 m, 4 s). Record the code, predicted and actual outputs with units. Explain why numeric conversion is needed and why the speed result can be a decimal. Label any paper traces. Square: side=int(input(...)); area=side*side; print with square-metre label. Outputs 25 and 64 square metres. Speed: distance=int(input(...)); time=int(input(...)); speed=distance/time; print with m/s label. Outputs 15.0 and 22.5 m/s. Division returns a float even when the numeric result is integral; both inputs still follow the whole-number requirement. Input returns text, so int is applied before numeric operations. Require two saved programs or accurately labelled paper versions, meaningful prediction/observation evidence and units. Do not claim that simply requesting a positive time validates it. Grown-up review; personal evidence is required.
Back to my workbook ↑

Curriculum & workbook reference

Computing for your homeschool day

Explore Casting with this free Grade 7 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

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.

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.

The book pages identify the related teaching topic. 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.