Programming Fundamentals & Data Types (OCR GCSE Computer Science)

Topic Questions

53 mins18 questions
14 marks

Tick (✓) one box in each row to identify whether the OCR Reference Language code given is an example of selection or iteration.

OCR Reference Language code

Selection

Iteration

for i = 1 to 10 print(i) next i

while score != 0 playgame() endwhile

if playerHit() then score = 0 endif

switch bonus: case 0: score = 9 case 1: score = 7 case 2: score = 5 endswitch

Did this page help you?

22 marks

Jack’s program uses the addition (+) arithmetic operator.

This adds together two numbers.

State the purpose of each of the arithmetic operators in the table

Arithmetic operator

Purpose

*

/

Did this page help you?

3a2 marks

Customers at a hotel can stay between 1 and 5 (inclusive) nights and can choose between a basic room or a premium room.

A typical booking record is shown in the table:

firstName

Amaya

surname

Taylor-Ling

nights

3

room

Premium

stayComplete

False

State the most appropriate data type for the following fields:

Nights

Room

3b1 mark

Give the name of one field that could be stored as a Boolean data type.

Did this page help you?

4a2 marks

A program is written to allow a user to enter the radius of a circle as a whole number between 1 and 30, then calculate and output the area of the circle.

Identify two variables used in the program

01 radius = 0

02 area = 0.0

03 radius = input("Enter radius")

04 if radius < 1 OR radius > 30 then

05 print("Sorry, that radius is invalid")

06 else

07 area = 3.142 * (radius ^ 2)

08 print (area)

09 endif

4b1 mark

Identify one item in the program that could have been written as a constant.

4c1 mark

Give one reason why you have identified this item as a constant.

4d1 mark

Tick (✓) one box in each row to identify whether each programming construct has or has not been used in the program in part (a).

Has been used

Has not been used

Sequence

Selection

Iteration

Did this page help you?

51 mark

A teacher asks students how long they spend completing homework. Students answer in minutes and hours (for example 2 hours 15 minutes).

The teacher would like to create an algorithm that will display students’ inputs in minutes only.

Identify the input and output required from this algorithm.

Input

Output

Did this page help you?

6a2 marks

State what is meant by a real data type and give an example of this data type.

6b2 marks

State what is meant by an integer data type and give an example of this data type.

Did this page help you?

71 mark

A programmer declares the following variables.

first = "Computer Science"

second = "is great"

State one difference between a variable and a constant.

Did this page help you?

8a1 mark

Write a pseudocode statement to assign the value 7.3 to a variable with the identifier timer

8b1 mark

State the most appropriate data type for the variable timer.

Did this page help you?

93 marks

OCR High School uses a computer system to store data about students’ conduct.

The system records good conduct as a positive number and poor conduct as a negative number.

A TRUE or FALSE value is also used to record whether or not a letter has been sent home about each incident.

An example of the data held in this system is shown below in Fig. 1:

StudentName

Detail

Points

LetterSent

Kirstie

Homework forgotten

−2

FALSE

Byron

Good effort in class

1

TRUE

Grahame

100% in a test

2

FALSE

Marian

Bullying

-3

TRUE

State the most appropriate data type used to store each of the following items of data.

StudentName

Points

LetterSent

Did this page help you?

102 marks

Identify two basic programming constructs that have been used in this algorithm.

01 for k = 1 to 3

02 for p = 1 to 5

03 print (k + p)

04 next p

05 next k

06 m = 7

07 print m * m

1

2

Did this page help you?

114 marks

An infinite loop is where a section of a program repeats indefinitely.

For each of the pseudocode algorithms shown below, tick the appropriate box to show whether they will loop infinitely or not.

Pseudocode

Will loop infinitely

Will not loop infinitely

01 x = 0

02 while True

03 print x

04 endwhile

01 x = 0

02 while x < 10

03 print x

04 endwhile

01 x = 0

02 while x < 10

03 print x

04 x = x + 1

05 endwhile

01 y = 5

02 for x = 1 to y

03 print x

04 next

Did this page help you?

12 marks

A teacher researches the length of time students spend playing computer games each day.

Tick (✓) one box to identify the data type you would choose to store the data and explain why this is a suitable data type.

Data Type

Tick (✓) one box

String

Integer

Real

Boolean

Explanation:

Did this page help you?

2a1 mark

DIV and MOD are both operators used in computing-related mathematics.

State the value of 13 DIV 4

2b1 mark

State the value of 13 MOD 4

Did this page help you?

31 mark

The symbol ^ is used for exponentiation.

Give the result of a^b when a = 3 and b = 2.

Did this page help you?

42 marks

Each member of staff that works in a restaurant is given a Staff ID. This is calculated using the following algorithm.

01     surname = input("Enter surname") 

02     year = input("Enter starting year") 

03     staffID = surname + str(year) 

04     while staffID.length < 10 

05         staffID = staffID + "x" 

06     endwhile 

07     print("ID " + staffID)

Define the term casting and give the line number where casting has been used in the algorithm.

Definition

Line number

Did this page help you?

14 marks

Identify and correct the errors in the Python program below.

Explain why each correction is necessary.

NAME = "Alice"

PI = 3.14159

name = "Bob"

NAME = "Charlie"

radius = 10

area = PI * radius ^ 2

print("The area of the circle is", area)

Did this page help you?

24 marks

Modify the Python code to include a selection construct that only adds even numbers to the total.

total = 0

for i in range(5):

num = int(input("Enter a number: "))

total = total + num

print("Total is:", total)

Did this page help you?

3a3 marks

Identify the output of each print statement in the following Python program:

a = True

b = False

print(a and b)

print(a or b)

print(not a)

Statement

Output

print(a and b)

print(a or b)

print(not a)

3b4 marks

Modify the code in part(a) to include a conditional that prints:

"Both are True" if both a and b are true

AND

"One is True" if either a or b is true but not both

Did this page help you?