Skip to content

2.2.2 Data types Practice Questions

GCSE · Paper 2 · Computational thinking, algorithms and programming · 9 practice questions · 31 marks

Exam questions for 2.2.2 Data types

9 practice questions (31 marks) with mark schemes

Answer each question, reveal the mark scheme, then award yourself marks. Scores and answers are saved in this browser so you can see which topics need more work.

Practice questions

  1. Question 1Practice question · J277/02 style5 marks

    A quiz program stores the data below. State the most suitable data type for each item. (a) The number of questions a player answered correctly [1] (b) The letter chosen as an answer (A, B, C or D) [1] (c) Whether the player has used a hint [1] (d) The time taken to answer a question, in seconds, such as 12.4 [1] (e) The player's email address [1]

    Show mark scheme

    (a) Integer (1) (b) Character (1) (accept string) (c) Boolean (1) (d) Real / float (1) (e) String (1)

    Mark yourself: how many marks did you get?
    / 5
  2. Question 2Practice question · J277/02 style2 marks

    A programmer stores the phone number 07700 900123 in a variable. Explain why a string is a better data type than an integer for this data. [2]

    Show mark scheme

    Any two of: An integer would remove / lose the leading zero (1) It contains a space (or + or other symbol) which an integer cannot store (1) No calculations are done with a phone number, so it does not need to be a number (1) Maximum 2 marks.

    Mark yourself: how many marks did you get?
    / 2
  3. Question 3Practice question · J277/02 style4 marks

    A program contains this code.

    01 a = "9"
    02 b = "4"
    03 print(a + b)
    04 print(int(a) + int(b))
    05 print(int(a) MOD int(b))
    06 print(int(a) / int(b))

    State the four values that are printed, in order.

    Show mark scheme

    Line 03: 94 (1) Line 04: 13 (1) Line 05: 1 (1) Line 06: 2.25 (1) Method: a and b are strings, so + joins them to give "94". Once cast, 9 + 4 = 13, 9 MOD 4 = 1 (9 is 2 remainder 1) and 9 / 4 = 2.25.

    Mark yourself: how many marks did you get?
    / 4
  4. Question 4Practice question · J277/02 style3 marks

    Complete the program so that it adds two prices entered by the user and prints a message. Write the missing function name for each gap.

    01 first = ________(input("Enter the first price"))
    02 second = ________(input("Enter the second price"))
    03 total = first + second
    04 print("Total: " + ________(total))
    Show mark scheme

    Line 01: float / real (1) Line 02: float / real (1) Line 04: str (1) Do not accept int for lines 01 and 02, because prices can have a decimal part.

    Mark yourself: how many marks did you get?
    / 3
  5. Question 5Practice question · J277/02 style3 marks

    State the data type of the result of each expression. (a) 15 / 4 [1] (b) 15 DIV 4 [1] (c) 15 > 4 [1]

    Show mark scheme

    (a) Real / float (1). The result is 3.75. (b) Integer (1). The result is 3. (c) Boolean (1). The result is True.

    Mark yourself: how many marks did you get?
    / 3
  6. Question 6Practice question · J277/02 style3 marks

    A programmer writes this code and finds that it does not work properly.

    01 age = input("Enter your age")
    02 if age > 17 then
    03     print("Adult")
    04 endif

    (a) Explain why the code does not work properly. [2] (b) Write a corrected version of line 01. [1]

    Show mark scheme

    (a) input() gives a string (1). A string cannot be correctly compared with the integer 17 using > / the comparison causes an error or gives the wrong result (1) (b) age = int(input("Enter your age")) (1)

    Mark yourself: how many marks did you get?
    / 3
  7. Question 7Practice question · J277/02 style4 marks

    A school stores data about its students. For each item, state the most suitable data type and give a reason for your choice. (a) A student ID such as S2041 [2] (b) The number of detentions a student has had [2]

    Show mark scheme

    (a) String (1) because it contains a letter / it is a label and no calculations are done with it (1) (b) Integer (1) because it is a whole number that is counted / it has no decimal part (1) Award the reason mark only if a type has been given.

    Mark yourself: how many marks did you get?
    / 4
  8. Question 8Practice question · J277/02 style4 marks

    Write a program, in the OCR Exam Reference Language or a high-level programming language, that asks the user to enter their age in years. The program must then print a message such as the one below for a user aged 15. [4] In 10 years you will be 25

    Show mark scheme

    Example answer:

    age = int(input("Enter your age"))
    future = age + 10
    print("In 10 years you will be " + str(future))

    (1) Age is input and stored in a variable (1) The input is cast to an integer (or real) (1) 10 is added to the age (1) The output text is joined to the number, with the number cast to a string using str(), and printed Accept the calculation inside the print statement, such as str(age + 10).

    Mark yourself: how many marks did you get?
    / 4
  9. Question 9Practice question · J277/02 style3 marks

    A program contains this code.

    01 print(int("12") + 5)
    02 print(str(12) + str(5))
    03 print(float("2.5") + 1)

    State the three values that are printed, in order.

    Show mark scheme

    Line 01: 17 (1) Line 02: 125 (1) Line 03: 3.5 (1) Method: int("12") is the number 12, so 12 + 5 = 17. str(12) and str(5) are strings, so + joins them to give "125". float("2.5") is 2.5, and 2.5 + 1 = 3.5.

    Mark yourself: how many marks did you get?
    / 3
General Exam Advice
  • •Practice answering questions under timed conditions
  • •Check your answers against the mark scheme carefully
  • •Focus on understanding the marking points, not just memorising answers
  • •Come back to the questions you dropped marks on a few days later