GCSE · Computer Science · OCR · Spec J277
Data type: Real
You type 5. The program prints 5.0. Nobody typed a decimal point, so where did that .0 come from? One small function did it.
Computer Science · Algorithms
Trace table — dry run the code
The same two-line program runs three times, with a different number typed in each time. Before each step, predict what lands in number, then step on and check.
Ready when you are — step through one line at a time.
Computer Science · Data types
Real or not?
Pick a value, then pick its box. The question every time: is this a decimal number?
Still to sort
Real (floating point) (0)
Holds a decimal number, such as 5.3.
Where the line is: Careful with the maths meaning. In maths, 5 is a 'real number' too. Here, real is the name of a data type, and it holds decimal numbers. So 5.0 is in; 5 is not.
Not a real (0)
A whole number, written without a decimal part.
Where the line is: A whole number like 5 isn't a real as it stands. Cast it with float and what comes back, 5.0, is.
You've seen what float hands back. Now sort some values yourself: which ones are real (floating point) numbers?
Find the cast
Look back at line 1 of the program you just stepped through.
Line 1 is number = float(input("Enter a number: ")). Several things happen in that one line. Which part is the casting?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Meet the data type for decimal numbers, and the one function that turns a 5 into a 5.0.
What you need to know
- Python uses data types so it can store and process information correctly.
- A real number holds a decimal number, like 5.3. Real and floating point are two names for it.
Have a goThree values: 7, 7.5 and 75. Which one is a real?
7.5.
It's the only decimal number. 7 counts as a real number in maths, but as a data type, real means a decimal number, and 7 and 75 are whole.
- To convert a value to a real, use the float function.
- Converting a value from one data type to another has a name: casting.
Have a goYour friend says casting is "when you save a value into a variable". Right or wrong?
Wrong. That's storing, not casting.
Casting changes a value's data type. Saving it into a variable just keeps it somewhere, and the type doesn't change.
- Cast a decimal such as 5.3 with float and you get 5.3 back.
- Cast a whole number and you still get a decimal: enter 5 and the output is 5.0.
Have a goSam types 12 into number = float(input()), then the program prints number. Sam bets you a biscuit the screen shows 12. Do you take the bet?
Take it. The screen shows 12.0.
Sam's assuming a whole number goes through untouched, but float gives back a decimal, even for a whole number.
- 5.0 is the same amount as 5. What's new is its data type: it's now a real.
- So never expect float to hand you back a whole number like 5.
The big picture
Python uses data types so it can store and process information correctly. A real (floating point) number holds a decimal number, such as 5.3. To convert a value to a real you use the float function, and converting a value from one data type to another is called casting. Cast a decimal such as 5.3 and you get 5.3; cast a whole number and you still get a decimal back, so entering 5 gives 5.0.
Key points
Worked example
Problem
A fitness app runs distance = float(input("Distance in km: ")). (a) One runner types 3. What is stored in distance, and what data type is it? (b) Another runner types 2.5. What is stored? (c) Name the process the float function is carrying out.
⚠ Watch out
Writing 5 as the result of float(5), because 5 is already a whole number. float converts the value to a real, so the result is the decimal 5.0: the same amount, with a new data type.
Memory hook
Whole number in, decimal out: float turns 5 into 5.0.
Check yourself
Close the lesson. Write one line of Python that asks for a height and stores it as a real. What would it store if someone typed 2, and what is that process called?
Flashcards
(8)Why does Python use data types?
What does a real (floating point) data type hold?
In number = float(input()), which part does the casting?
Which Python function converts a value to a real?
What is casting?
5 is entered into a program that casts it with float. What is output?
Is 5.0 a whole number or a real?
Does float only work on numbers that already have a decimal part?
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 postedMore OCR GCSE Computer Science topics
- Boolean operators AND, OR, NOT
- Casting
- Constants
- Data type: Boolean
- Data type: Character and string
- Data type: Integer
- File handling: open, read, write, close
- Inputs, outputs, assignments
- Iteration (count- and condition-controlled loops)
- Local and global variables
- Operators (arithmetic and Boolean)
- Random number generation
How this lesson was checked. This OCR GCSE Computer Science (specification J277)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 3 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.