ScholaFly

CS12-02 Computer Science Watch

Data types

Watch on YouTube

In this lesson

Data types: how to define a data type as the kind of value a variable holds, with worked examples and the mistakes examiners report. AQA 8525, Edexcel 1CP2 and OCR J277 GCSE. Programming basics 2 of 9. More at https://scholafly.com

By the end: Define a data type as the kind of value a variable holds, which decides what the program can do with it; name the five - integer, real (float), Boolean, character and string - with one example of each; choose the right one for a piece of data in a scenario and give the reason; and know the language names that differ (real is float in Python; Python has no separate character type).

What it covers

  1. 0:00 Intro: data types
  2. 0:33 Data types
  3. 1:49 Five data types
  4. 4:10 Choosing a type
  5. 6:15 The first line

Key words

About this video

Data types | GCSE Computer Science | CS12-02

Data types: how to define a data type as the kind of value a variable holds, with worked examples and the mistakes examiners report.
AQA 8525, Edexcel 1CP2 and OCR J277 GCSE. Programming basics 2 of 9.
More at https://scholafly.com

Watch first: CS12-01 - https://youtu.be/TWrzTKpBotA
Video code: CS12-02 (search "ScholaFly CS12-02")

#GCSEComputerScience #ProgrammingBasics #DataTypes

For teachers
This GCSE Computer Science lesson teaches data types. By the end, students should be able to define a data type as the kind of value a variable holds, which decides what the program can do with it; name the five - integer, real (float), Boolean, character and string - with one example of each; choose the right one for a piece of data in a scenario and give the reason; and know the language names that differ (real is float in Python; Python has no separate character type). It works through four worked examples and the mistakes examiners report.

Exam board specification references:
AQA 8525
- 3.2.1
Edexcel 1CP2
- 6.3.1
OCR J277
- 2.2.2

Read the transcript

Picture a sign-up form that saves each phone number as a number, to save space. What could go wrong? No crash, no error, so it looks fine. But a zero at the front of a number is worth nothing, so it is dropped, and every phone number loses its first digit. Nobody can be called back, because the data was kept as the wrong kind of thing.

A data type is the kind of value a variable holds, and it decides what the program can do with that value. The type changes what an operator does. Five plus five gives ten. Put each five inside quotation marks, and the same plus sign joins them end to end, giving the text five five. The values look alike, but the type changed what the plus sign did. Turning one type into another on purpose is a separate skill, and the video Casting teaches it. One examiner's report says it was disappointing to see that only twenty per cent of students could correctly describe what a data type was. There were very few answers mentioning variables storing the data and a lot of incorrect answers referred to the type of data. The fix is to stop leaning on the word being defined. Say the kind of value a variable holds, and say that it decides what the program can do with it.

Five data types appear on every course's list, and each holds a different kind of value. An integer is a whole number, positive, negative or zero, such as forty-two or minus seven. A real is a number with a decimal part, such as three point seven five. Python calls it a float. A Boolean holds one of only two values, True or False, and nothing else. A character is one single letter, digit or symbol, such as a capital G. A string is a sequence of characters, such as the word Hello. Python keeps no separate character type, so one character there is a string of length one. In code, a string sits inside quotation marks, and that is the giveaway. Forty-two with no marks round it is an integer. Forty-two inside them is a string, even though it looks like a number. What type is each: three point nought, three in quotes, and True? Real, string and Boolean. Three point nought has a decimal point, so it is a real, and the point settles it. Questions may print the general name real. But some courses mark code written in C sharp, Python or VB dot NET. If yours does, write your own language's name in a coded answer, which is float in Python, because none of those three has a type called real. One course also lists arrays and records, types that hold many values at once. Those come later, in the video Arrays, one and two dimensional.

Choosing a type for a piece of data comes down to four checks, made in order. A value that could ever have a decimal part is a real. A value that can only ever be one of two states, like on or off, is a Boolean. A whole number you will count or calculate with is an integer. Anything that must be kept exactly as typed, letters, spaces or a zero at the front, is a string, and one symbol on its own is a character. A cinema booking program stores five things: how many tickets, the price paid, whether the booking is confirmed, the customer's phone number, and the letter of the row. Which type fits the number of tickets, and which fits the price paid? Integer for the tickets, because nobody books half a ticket. Real for the price, because pounds and pence need a decimal part. Try the other three: confirmed, phone number and row letter. A type for each? Boolean for confirmed, since it is only ever True or False. Character for the row letter, one symbol. And string for the phone number. Now say why the phone number is a string when it is all digits. It has to keep its leading zero, and nobody ever adds or multiplies phone numbers. Kept as text, every digit stays exactly as typed.

A wrong type usually slips in on the very first line that gives a variable its value. One program starts area at zero, and a following line puts the area of a circle into it. What is wrong with area equals zero as that first line? Zero with no decimal point is an integer, but a circle's area is almost never a whole number. The first value should be a real. Python would happily switch the type afterwards, but the first value is what tells a reader what kind of value the box holds. One examiner's report puts it this way. The most frequent error was initialisation of the variable for the area of a circle to an integer value, rather than a real value, with a decimal. The fix is two characters. Write area equals nought point nought, and the variable starts life as a real. A second program sets isMember equals False, with the word False written inside quotation marks. Here's the question: what type is isMember now, and what should the line be? A string, because of the quotes. Remove them, and isMember holds the Boolean value instead. One examiner's report names the misuse of quotation marks, either missing them on strings or adding them to integers. So quotation marks go round text and nowhere else. A string without them is read as a variable's name, and a number inside them will not add. Some functions give back True or False. Here are two IF lines that use one called hasPaid. Line A compares it with True. Line B uses hasPaid on its own. Which line works in Python: A, B, or both? Both work. The value is already a Boolean, so it can stand as the whole condition by itself. One examiner's report, on a question where a function's result was used in an IF, says this. Many candidates found this question challenging. The question relies on understanding of how selection statements operate. The answer of Boolean can be inferred from how the function return value is used. The way to read it: a condition comes out True or False, so a value that stands as the whole condition is read as a Boolean.

The definition, the five types and the four checks get put to work on data this video never stored. What type should hold a temperature such as minus four point five? Real, or float in Python. It has a decimal part, and the minus sign does not change that. Here's a different one: a postcode with letters, digits and a space. Which type? String. It mixes characters of every kind, and nobody calculates with a postcode. Try the definition itself: what is a data type? The kind of value a variable holds, which decides what the program can do with it. One more, back at the sign-up form: what single change saves every first zero? Store each phone number as a string. Kept as text, the zero stays, and every customer can be called back.

If the five types feel locked in, a thumbs up marks this video as covered, so you never have to sit through it again. If they do not yet, save it for later; sorting ten things from your own bag into types makes it feel routine.

Next in the chapter: Casting. Hopefully that's next in your feed, but if not, search for ScholaFly C S twelve, oh three.

Every other video is on scholafly.com too, easy to search by video code or by keyword. Whatever you're revising, go there and have a look, or, watch the next video.

Related terms

For: AQA GCSE 8525, Edexcel GCSE 1CP2, OCR GCSE J277

On the specification

BoardSpecStatement
AQA GCSE 85253.2.1Explain the concept of a data type and use integer, real, Boolean, character and string appropriately.
Edexcel GCSE 1CP26.3.1Write programs using primitive data types (integer, real, Boolean, char) and one- and two-dimensional structured types (string, array, record).
OCR GCSE J2772.2.2Data types
For teachers

This GCSE Computer Science lesson teaches data types. By the end, students should be able to define a data type as the kind of value a variable holds, which decides what the program can do with it; name the five - integer, real (float), Boolean, character and string - with one example of each; choose the right one for a piece of data in a scenario and give the reason; and know the language names that differ (real is float in Python; Python has no separate character type). It works through four worked examples and the mistakes examiners report.