GCSE · Computer Science · Eduqas · Spec C500QS

Using a variety of data types

You type 1, then 2. Your program prints 12. The fix works perfectly, until someone types the word four.

Computer Science · Data types

You typed 1 and 2. Why does it print 12?

Run the same program twice, on different inputs. Make your call before each answer appears.

Pick an input, then step through. At each marked line, call the result before it appears.

first = input("First number: ")
second = input("Second number: ")
print(first + second)
total = int(first) + int(second)
print(total)

Variables

first="1"

Step 1. You type 1. input() hands it back as the string "1". The quote marks show it is text, not a number.

Step 1 of 5Called right: 0 of 2

Ask of every value: what type is it right now, and what will + do to that type?

Computer Science · input()

What is the program actually holding?

The program runs age = input("How old are you? ") and the user types 15.

Which is closest to what age holds right now?
How sure are you?

Exam line: After age = input(...), age holds a string. Cast it with int() or float() before any calculation.

Computer Science · Choosing a type

Which type would you give each item?

Sort each item of data into the type that suits it best.

Still to sort

Integer (0)

Whole numbers.

Where the line is: No fractional part. Counts of things are usually integers.

Real (0)

Numbers with a fractional part (floating point).

Where the line is: If it can have a decimal part, such as pounds and pence, it is real.

Boolean (0)

Two states: true or false.

Where the line is: Use it when the only possible answers are yes or no.

String (0)

Text. It can hold letters, digits and symbols.

Where the line is: Digits you never calculate with belong here.

Char (0)

A single character, in pseudocode and other languages.

Where the line is: One character only. Python itself holds a single character as a string of length one.

6 of 6 still to sort.

Every item gets exactly one type. Ask what it holds, and what the program will do with it.

Exam line: Choose the type from what the item holds and how it will be used: whole numbers as integer, values with a fractional part as real, two-state values as Boolean, text as string, a single character as char.
Watch out: Made of digits does not mean number. If you will never add it, average it or compare its size, a string is the better choice.

​

Computer Science · Casting

One 5, three types

  1. 1 Explore
  2. 2 Spot the mismatch

Model. A cast does not change the original value. It returns a new value in the new type. The three forms of 5 are shown side by side.

Step 1 · Explore

Select each form of 5 in the key and see the cast that makes it and what + does with it.

Linked parts: select one to follow it through every representation

The string

The integer

The real number

One value, written three ways. The quote marks and the point matter.

Linked parts tried: 0 of 2.

Computer Science · Casting in your own code

Finish the ticket program

A program asks how many tickets are wanted at £4 each, then prints how much is owed. Choose the missing line each time it asks.

  1. tickets_text = input("How many tickets? ")Whatever is typed, this holds a string.
  2. missing step
Which line is step 2?

Exam line: Cast an input with int() before you calculate, and cast the number back with str() to join it into text.

Computer Science · Exam practice

Explain the bug, then the crash

a = input("First number: ") b = input("Second number: ") print(a + b)

This program is meant to add two numbers. When the user enters 4 and then 5 it prints 45. Explain why it prints 45, how to fix the program, and why the fixed program can still crash when it is run. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

Exam line: Say what input() returns, what + does to two strings, how casting fixes it, and why a word still crashes the program.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Why the type of a value decides what your program can do with it.

What you need to know

  • A data type is the kind of data a computer can store and the actions you can perform on it.
  • An integer stores whole numbers. Real (floating point) numbers hold decimal numbers. A Boolean holds true or false.
  • A string holds text, but it can also hold digits and symbols. Char is a single character.
  • Choose a type from what the item holds and how it will be used. Digits you never calculate with, like a phone number, go in a string.
  • Have a goDev stores whether a pupil handed in their homework as an integer. Dev's friend says that is odd. Who is right, and what type fits better?

    The friend. A Boolean fits better: true or false.

    Choose the type from what the item holds. Handed in or not has two states, which is what a Boolean is for, not a count of whole numbers.

  • A program needs to know the type to process data correctly. You can't do calculations with strings.
  • input() returns a string, even if you type a number.
  • Have a goA user types 3.5 at an input() prompt. Before any casting, is the program holding a real number or a string?

    A string: "3.5".

    input() returns a string even when what you typed looks like a number. Casting comes later.

  • Adding two strings joins them together. So an uncast 1 and 2 give 12, not 3.
  • Casting changes a value's type. Use str() for a string, int() for an integer and float() for a real number.
  • Have a goYou hold the string "20" and want to add 5 to it. Which cast do you reach for?

    int() (or float()), to turn it into a number first.

    You can't do calculations with strings, so the value has to be cast to a number before the sum.

  • To calculate with an input, cast it with int() or float() first. Float on 5 gives 5.0, which may not be what you wanted.
  • Casting can still fail: type the word four and an error happens when the program runs, and it crashes.

The big picture

Every item of data has a data type, which decides what a program can store and do with it. input() always returns a string, so two uncast inputs are joined, cast inputs are added, and text that is not a number crashes the program when it is cast.

Key points

1A data type decides what kind of data a value is and what a program can do with it.
2The types to know are integer, real (floating point), Boolean, string and char (a single character).
3input() always returns a string, so cast with int() or float() before calculating.
4Two strings added with + are joined together, so uncast inputs 1 and 2 give 12.
5Casting can still fail: text such as the word four cannot be converted and the program crashes when it runs.

Worked example

Problem

A shop program asks for the price of one pencil, typed as 2.5 (pounds), and prints the cost of two pencils as "Cost: " followed by the cost. Make it work.

⚠ Watch out

Thinking a number typed at an input prompt reaches the program as a number. It does not: input() returns a string, so cast it with int() or float() first, and text that is not a number still crashes.

🧠

Memory hook

Before every +, ask: what type is each value right now? Strings join, numbers add, and input() always starts as a string.

✓

Check yourself

A program prints a + b, where a and b both come from input(). A user types 6 and 9. What prints, and what change would print 15?

Flashcards

(13)
What does a data type define?
The kind of data a computer can store, and the actions you can perform on it.
What does an integer store?
Whole numbers.
What does a real (floating point) number hold?
Decimal numbers: numbers with a fractional part.
What does a Boolean hold?
True or false.
What can a string hold?
Text, but also digits and symbols.
What is char short for, and what does it hold?
Character. A single character.
What is casting?
Changing the data type of a piece of data from one type to another.
Which function converts a value to a string?
str()
Which function converts a value to an integer?
int()
Which function converts a value to a real number?
float(), so float on 5 gives 5.0.
What type does input() return in Python?
A string, even if you type a number.
What happens when + is used on two strings?
They are joined together, so "1" + "2" gives "12".
Why can a program still crash after you cast an input?
If the user types text that is not a number, such as four, it cannot be converted. An error occurs when the program runs.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More Eduqas GCSE Computer Science topics

See the full Eduqas Computer Science curriculum →

How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 16 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.