Question bank › GCSE › GCSE Computer Science › Programming fundamentals

Data types and casting

10 questions43 marksabout 50 min

Answer on paper first, then reveal the mark scheme one mark at a time.

1Grade 1–34 marks

A gym stores details about each member. State the most suitable data type for each item.

DataExample
Age15
Phone number07700 900123
Height in metres1.72
Has paidtrue

[4]

2Grade 1–35 marks

Five values that a program stores are shown below.

ValueData type
'Y'
"Yes"
3.0
-7
False

Complete the table by writing the most suitable data type next to each value. Each data type may be used once, more than once or not at all. [5]

3Grade 4–54 marks

A program asks the user for their age and then displays their age next year. The code is written in OCR Exam Reference Language.

01 age = input("Enter your age")
02 nextYear = age + 1
03 print(nextYear)

(a) The user enters 16. State the data type of age after line 01 has run. [1]

(b) Explain why line 02 does not calculate the age next year correctly. [2]

(c) Rewrite line 01 so that the program works correctly. [1]

Stuck on Data types and casting?

Get it sorted in a free 30-minute session

We work through your weakest questions on this topic on Zoom. I reply the same day.

4Grade 4–54 marks

Each of the following lines of code is run on its own. Give the output of each line.

(a) print(3 + 4) [1]

(b) print(str(3) + str(4)) [1]

(c) print(int("12") * 2) [1]

(d) print("7" + "5") [1]

5Grade 6–75 marks

A car park charges £1.50 for each hour or part of an hour. A program stores the time parked, in hours, in a real variable called hours.

wholeHours = int(hours)
chargeHours = wholeHours + 1
charge = chargeHours * 1.50
print("Pay £" + str(charge))

(a) A driver parks for 2.75 hours. State the value of wholeHours and the value of charge. [2]

(b) Describe what happens to a real value when it is cast to an integer using int(). [1]

(c) The program gives the wrong charge when hours is exactly 3.0. State the charge the program gives, and the charge it should give. [2]

6Grade 4–54 marks

A weather station records readings every hour. Two of the items it stores are:

  • the air temperature, for example 21.6
  • a National Insurance number for the member of staff on duty, for example QQ 12 34 56 C

For each item, state the most suitable data type and justify your choice. [4]

7Grade 6–74 marks

A program counts the number of tickets sold. Part of the program is shown below.

01 sold = 27
02 print("Tickets sold: " + sold)
03 sold = sold + 1

(a) Explain why line 02 causes an error when the program runs. [2]

(b) Rewrite line 02 so that it displays Tickets sold: 27 without an error. [1]

(c) A student says: "After line 02 is fixed, sold will be a string, so line 03 will no longer work." Explain why the student is wrong. [1]

8Grade 6–74 marks

Each expression below is evaluated in a program. Complete the table by giving the value of each expression and the data type of the result. [4]

ExpressionValueData type of result
5 / 2
5 DIV 2
5 > 2
"5" + "2"
9Grade 8–95 marks

The scores from a quiz have been read from a text file into an array. Because they came from a file, every score is stored as a string.

array scores = ["12", "7", "9"]

(a) A student writes the following code to add up the scores.

total = ""
for i = 0 to 2
    total = total + scores[i]
next i
print(total)

State the output of this code. [1]

(b) Write an algorithm, using OCR Exam Reference Language or a high-level language, that uses casting to calculate and output the correct total of the three scores. [4]

10Grade 6–74 marks

A smart-lock program stores whether the front door is locked. The programmer stores this as a string with the value "yes" or "no". It also stores the grade a user has given the lock (A, B, C, D or E) as a string.

(a) State a more suitable data type for storing whether the door is locked, and give one advantage of using it. [2]

(b) State a more suitable data type for the grade, and explain why it is more suitable than a string. [2]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session