The same keys can make text or a number, and the computer does different things with each. Numbers can be added: 12 and 3 make 15. Text can only be joined: 12 and 3 make 123. So programs store things you'll do maths with as numbers, and things like names and phone numbers as text.
12 and 3 make 15. But a computer can also turn 12 and 3 into 123. How does it know which to do?
What you should already know:
Letters are numbers· A computer can only store numbers, so every letter has its own number, called its code.
When you type 12, the computer has to decide: is it the number twelve, or the two characters 1 and 2?
How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
Predict: Read the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
Try: Try it on the board and compare the result with your prediction.
Investigate: Work out why it happens, one step at a time.
Modify: Change the problem on purpose and see what happens.
Practise: A few on your own, to check you have it.
Make: Make your own problem using what you have learned. Expect a few tries; that is normal.
Make your prediction first. Help opens once you've locked it in.
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
Join or add?
TryTry it on the board and compare the result with your prediction.
Try: type 12 as text
Was your guess right?
Try it yourselfYour edits are saved in this browser.
Type 12 in the box. How many numbers does the computer store for it?
Use the board. This ticks when you get there.
InvestigateWork out why it happens, one step at a time.
Worked example: same keys, different jobs
Worked exampleBefore each step, say what you think comes next.
12+3=15Stored as numbers: the computer adds them.
12 joined to 3=123Stored as text: the computer puts one after the other.
"12"→49,50As text, 12 is two characters, each with its own code.
the type decidesNumber or text: the computer stores which one it is, and that decides what it can do.
Now: which can be added?
Sam joins two text boxes. Click the line where it first goes wrong.
ModifyChange the problem on purpose and see what happens.
Vary: what happens?
5 and 4 are stored as numbers. The computer adds them. What does it show?
Now 5 and 4 are stored as text. The computer joins them. What does it show?
PractiseA few on your own, to check you have it.
Which type?
Review: A is 65. What number is the letter F?
MakeMake your own problem using what you have learned. Expect a few tries; that is normal.
Design a sign-up form
Then: think of a box on a real form. Would a number or text be safer?
You're making the sign-up form for the Coding Club. For each box, choose how to store it.
How many robots each member builtThe club adds them up for a total.
Member's nameNames are joined and sorted, never added.
Parent's phone numberNobody adds phone numbers, and the 0 at the front must stay.
PostcodeIt's a label for a place, not an amount.
Points earned this termPoints get added up.
Year levelThe club works out next year's level by adding 1.
Lesson done. You've finished every step you need.
Now you can
Say what a computer does with numbers and with text.
Explain why 12 and 3 can make 15 or 123.
Choose whether a form should store something as a number or as text.
Students see that 12 typed as text is two characters with their own codes, compare adding numbers with joining text, and choose number or text for each box on a sign-up form (AC9TDI6K03 node 2). About 35 minutes.
I can say what a computer does with numbers and with text.
I can explain why 12 and 3 can make 15 or 123.
I can choose whether a form should store something as a number or as text.
Before class
Do the Try board yourself: type 12, then 123.
The one idea: the type of data (number or text) decides what the computer can do with it. Numbers add; text joins.
Simplification: in programs this is "string" and "integer"; spreadsheets show it as a number lined up on the right and text on the left. Neither word is needed here.
Year 7–8 catch-up: Text as numbers (8K03 n2) assumes students know a digit in text is a character; this lesson is that idea.
Running the lesson
Predict: students who chose 15 added; ask what joining two words does.
Try: ask why 12 needs two numbers here but would need one as a number.
Worked example: ask what goes wrong if a phone number loses its 0.
Make: let pairs argue about year level; adding 1 next year is the deciding job.
The hard part (on purpose)
Thinking text that looks like a number is a number. Have them type 12 on the board and count the codes.
When students get stuck
A student says the computer adds text that looks like numbers (Sam's mistake). Ask: What does joining cat and fish make? Now join 12 and 3. Fix: Text joins; only numbers add.
A student says a phone number is a number. Ask: Would you ever add two phone numbers? Fix: No maths, and the leading 0 must stay: text.
Stretch and support
Stretch: A spreadsheet shows 0412 as 412. What happened, and how could you stop it?
Support: A card: Number: add, take away, compare sizes. Text: join, sort A to Z, keep every character.
Where it leads
Next: On or off (how switches store numbers).
Year 7–8: Everything is numbers; in Code, Python console › Text into numbers (int()).
What each step is for
join or add?: Committing to what joining two pieces of text shows tests the new move: text is joined, not added.
Try: type 12 as text: Typing 12 as text and seeing two codes settles the prediction: as text, 12 is two characters, not the number twelve.
Worked example: same keys, different jobs: Doing 12 and 3 both ways models the move. Sam adds two pieces of text, the mistake planted after the method.
Vary: what happens?: Each task changes the type or the job: add numbers, join text, then join words.
which type?: Choosing the type from what the program will do with it, and a review of letter codes.
design a sign-up form: Sorting a form's boxes by what the program will do with them reverses the move: students choose the type.