0% found this document useful (0 votes)
32 views4 pages

Year 10 Programming Test

Uploaded by

r4ryanjohn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views4 pages

Year 10 Programming Test

Uploaded by

r4ryanjohn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. A teacher at a school sports day records the times of students in a race.

The time of each racer is given in seconds. For example, 102.3 seconds would be given
if a racer took 1 minute 42.3 seconds.
Valid times can be entered between 1 and 3600 inclusive. If an invalid time is entered,
an error message is output.
(a) Complete the following program to output "Invalid input" if the time entered
is not valid.
You must use either:
 OCR Exam Reference Language, or
 A high-level programming language that you have studied.
seconds = input("Enter seconds for race")

if seconds < 1________ or seconds > 3600__ then


print("Invalid input")
endif

(b) A program is created that will convert the number of seconds taken in a race into
minutes and seconds. A sub program will be used for the conversion.
For example, if 102.3 seconds is input, the output will be 1min42.3.
Complete the program.
You must use either:
 OCR Exam Reference Language, or
 A high-level programming language that you have studied.
seconds = float(input("Enter seconds for race"))
outputString = convertToMin(seconds)
print(outputString)
def convertToMin(seconds)
minutes = seconds/60
print(minutes”min”)________________________________________
endfunction
Five runners’ times for the 100 metres race have been stored in an array named
oneHundred which is shown in the following table.

0 1 2 3 4
12.5 12.3 10.4 11.25 10.9

(c) The following line of code is run:


racers = oneHundred.length
State the value stored in the variable racers once the line of code has been run.

10.9
2. Customers at a hotel can stay between 1 and 5 (inclusive) nights and can choose
between a basic room or a premium room
(a) A typical booking record is shown in the table:

(i) State the most appropriate data type for the following fields:
Nights
Integer................................................................................................................................
Room ......Char...........................................................................................................................
[2]
(ii) Give the name of one field that could be stored as a Boolean data type.
True [1]
(b) A Basic room costs £60 each night. A Premium room costs £80 each night.
(i) Create a function, newPrice(), that takes the number of nights and the type of room
as parameters, calculates and returns the price to pay.
You do not have to validate these parameters.
You must use either:
• OCR Exam Reference Language, or
• a high-level programming language that you have studied.
price = 0
def newPrice(nights,room)
nights = int(input(“How many nights did you stay”))
room = input(“What room type did you stay in? Enter Basic or Premium”)
if room = Premium
price = 80 * nights
else:
price = 60 * nights
print(price)
[4]
(ii) Write program code, that uses newPrice(), to output the price of staying in a Premium
room for 5 nights. You must use either: • OCR Exam Reference Language, or • a high-level
programming language that you have studied.
room = Premium
nights = 5
newPrice(nights,room)

nights = 5
room = Premium

Price = nights * 80
print(Price)

You might also like