A programmer has started to write a program using Python. Their program is shown in Figure 6.
The program should generate and output 10 numbers, each of which is randomly selected from the numbers in a data structure called numbers.
The program uses the random module.
For example, random.randrange(0, 8)
would generate a random integer between 0 and 7 inclusive.
One possible output from the finished program would be 11, 14, 14, 42, 2, 56, 56, 14, 4, 2
• Line numbers are included but are not part of the program.
Figure 6
1 import random
2 numbers = [ 11, 14, 56, 4, 12, 6, 42, 2 ]
3 count = 0
4 while count < 10:
5 count = count + 1
6 number = random.randrange(0, 8
7 print(numbers[count])
The program shown in Figure 6 contains a syntax error.
Identify two choices to indicate the statements that are true about syntax errors.
A syntax error can be found by testing boundary values in a program.
A syntax error is a mistake in the grammar of the code.
A syntax error is generally harder to spot than a logic error.
A syntax error will stop a program from running.
An example of a syntax error is trying to access the fifth character in a string which only contains four characters.
The program shown in Figure 6 also contains a logic error.
Identify the line number that contains the logic error, and correct this line of the program.
Your corrected line must be written in Python.
Did this page help you?