Lesson 4.1.1.8
4.1.1.8 Random numbers and exception handling Quiz: AQA Computer Science, Unit 1
20 questions
In partnership with Revision Ninja
Lesson 4.1.1.8, Random numbers and exception handling: 20 multiple choice questions for the AQA Computer Science (7517), Unit 1: Fundamentals of programming, written with Revision Ninja.
Host it live on the board and students join with a game code on their own devices, or revise alone with Free Play. The answers are revealed in the game.
The 20 questions
-
What does random number generation in a program produce?
- The same number every time the program runs, because the generator begins from a fixed starting point
- Values chosen by a random process, not fixed in advance by the programmer
- Only prime numbers, selected by a fixed rule that the programmer must supply each time
- A memory address for each variable, which the operating system assigns when the program starts
-
A program needs a whole number between 1 and 6 inclusive, such as to simulate a die. Which description fits?
- A constant value of 6, which is fixed and never changes between program runs
- Random real number between 0 and 1, including fractional values such as 0.5
- Random integer in the range 1 to 6
- A Boolean value of TRUE or FALSE, which is used to decide the outcome of a test
-
What is an exception in programming?
- A named constant with a fixed value
- A standard statement that always runs in sequence
- An unexpected event or error that interrupts normal execution
- A type of loop that repeats forever
-
What is the purpose of exception handling?
- To store values in binary files only, so that they can be read by other programs later
- To remove the need for selection and iteration, so that the program runs in a single pass
- To make every variable into a constant, so that no value can ever be changed by mistake
- To detect an error and respond to it without the program crashing
-
Which language construct usually detects and handles an exception such as division by zero?
- A string concatenation
- A constant declaration
- Try and catch blocks
- A FOR loop with a fixed count
-
A program divides by a number entered by the user. Which action is most sensible if the user enters 0?
- Store 0 as a constant and use that value in every later division in the program
- Remove all selection from the program, so that no check is needed on the input value
- Catch the exception and ask for a valid non-zero number
- Multiply the result by zero, so that the division has a valid answer despite the error
-
A random integer generator is asked for a value between 10 and 20 inclusive. Which statement is correct?
- Only the value 15 is returned, because the midpoint of the range is always selected
- Values below 10 are returned about half the time, since the lower part of the range is favoured
- Any integer from 10 to 20, including both ends, may be returned
- Only real numbers are returned, because the generator cannot produce whole numbers
-
A program uses random numbers for a game. Which result is most likely to appear wrong to a player if the random generator is not called correctly?
- No value at all, because the random generator is not allowed to be used in a game program
- Random values that differ between runs, which is the expected behaviour of a generator
- A value outside the requested range, caused by an off-by-one error in the generator's bounds
- The same value repeating every time, which seems predictable
-
Which statement best describes why exception handling is needed when reading a number typed by a user?
- The input might not be a valid number, so the program must catch the problem
- Users cannot type numbers into a program, so the input must come from a file instead
- Numbers typed by users are always invalid, so every entry must be rejected by the program
- Exception handling replaces all variables, so that the program stores its data in exceptions
-
A random integer from 1 to 4 is generated, and one is added to it. What range of values is possible?
- 1 to 4
- 2 to 5
- 0 to 4
- 1 to 5
-
A simulation needs a random real number between 0 and 1. Which is the best description?
- A string of digits such as 0.5, which must be converted before it can be used in sums
- A Boolean value of TRUE or FALSE, which is used to decide the outcome of a yes-or-no test
- Random real with a value from 0 up to but not including 1 (or up to 1)
- Random integer of 0 or 1 only, which gives just two possible outcomes for each call
-
A program catches an exception but then continues with an unusable value. What is the main problem?
- The exception handling has made the program faster
- The exception has been stored as a constant
- The program now uses too few variables
- The handler does not recover the program state correctly
-
Which benefit does exception handling bring to a quiz program that reads a score as text?
- It converts every score to a Boolean, so that only pass or fail results are ever stored
- It removes the need for scores entirely, so the quiz only records whether each answer is correct
- It makes the quiz run without any input, so that the scores are generated automatically by the system
- It stops invalid input breaking the quiz and lets the user retry
-
A random number generator gives the value 3 on a call. Which statement about the next call is correct?
- It must be 3 again because the generator has memory of the last value
- It must be less than 3 always
- It is not guaranteed to be 3, since each call is an independent selection
- It must be 4
-
A program uses a random integer to pick one of 5 questions. Which range and index is used if the questions are stored from index 0?
- Random integer from 0 to 5
- Random integer from 0 to 4
- Random integer from 1 to 5 only
- Random real from 0 to 5
-
Which statement about exception handling is correct?
- It is the same as a random number generator, because both produce values that are not predictable
- It is only used for mathematical operations, such as division and square roots, and nothing else
- It separates the normal code path from the code that responds to errors
- It requires the program to stop before any error can occur, so that errors never reach the user
-
A program needs to simulate a fair coin. Which is most suitable?
- A constant value of 1 that is always the same, which would give the same result each time
- A string of length 10 that holds the words heads and tails in a fixed order each time
- Random integer from 0 to 1, with 0 for heads and 1 for tails
- Random real from 0 to 100, which gives a value that is then compared with 50 to decide heads
-
Why must a random number generator be used with a specified range rather than producing any value?
- Because random values are always negative
- So that the program no longer needs variables
- Because random values can only be integers less than zero
- So the output fits the needs of the program, such as valid indexes
-
A program uses random numbers and exception handling together. Which combination best describes its design?
- The program avoids all selection and iteration
- Random values are stored as constants and never change
- Exceptions create random numbers in every loop
- Random values drive behaviour while errors are caught and handled
-
What is the chance of a fair six-sided die giving a 6 on one roll?
- 1 in 36
- 1 in 2
- 6 in 1
- 1 in 6
Related quizzes
- Data types Quiz · 4.1.1.1 · 20 questions
- Programming concepts: sequence, selection and iteration Quiz · 4.1.1.2 · 20 questions
- Arithmetic operations Quiz · 4.1.1.3 · 20 questions
- Relational and Boolean operations Quiz · 4.1.1.4 · 20 questions
- Constants and variables Quiz · 4.1.1.6 · 20 questions
- String-handling operations Quiz · 4.1.1.7 · 20 questions
- Subroutines Quiz · 4.1.1.10 · 20 questions
- Parameters and returning values Quiz · 4.1.1.11 · 20 questions
- Local and global variables Quiz · 4.1.1.13 · 20 questions
- Stack frames in subroutine calls Quiz · 4.1.1.15 · 20 questions