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.

1number = float(input("Enter a number: "))
2print(number)
run
typed in
number
data type of number
Output
Press Start to run the first line.
·

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.

6 of 6 still to sort.

You've seen what float hands back. Now sort some values yourself: which ones are real (floating point) numbers?

Watch out: 5 and 5.0 are the same amount, but only one of them is a real. Don't sort by size; sort by whether it's a decimal number.

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?

Computer Science · Casting

What does float do to a whole number?

A program runs number = float(input("Enter a number: ")) and the user types 5.

Which is closest to what you think ends up in number?
How sure are you?

Computer Science · Exam practice

Choose it, cast it, justify it

A shop's program asks the user to type in the price of an item, such as 2.49. State the data type the price should be stored as, name the function used to cast it, and justify your choice of data type. [3 marks]

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

Exam line: A full answer names the data type, names the casting function and links the choice to the kind of value being stored.

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

1Data types let Python store and process information correctly.
2A real (floating point) number holds a decimal number, such as 5.3.
3The float function converts a value to a real.
4Casting is converting a value from one data type to another.
5Casting a whole number with float gives a decimal: 5 becomes 5.0.

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?
So it can store and process information correctly.
What does a real (floating point) data type hold?
Decimal numbers, such as 5.3.
In number = float(input()), which part does the casting?
float(): it converts the value to a real. input() only brings the value in.
Which Python function converts a value to a real?
The float function: float().
What is casting?
Converting a value from one data type to another.
5 is entered into a program that casts it with float. What is output?
5.0, a floating point number, not 5.
Is 5.0 a whole number or a real?
A real. It's the same amount as 5, but it's written as a decimal number.
Does float only work on numbers that already have a decimal part?
No. It works on whole numbers too, and gives back a decimal, such as 5.0 for 5.

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 OCR GCSE Computer Science topics

See the full OCR Computer Science curriculum →

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.