Back to the topic

The mark scheme starts on a new page, so you can print pages one and two for a student and keep the last page yourself. Everything prints in black on white whichever theme you are using.

Python · 1.1

First Steps: Output, Comments and Errors

Section A: 10 multiple choice questions, 10 marks. Section B: 5 written questions, 14 marks. Total 24 marks.

Name

Class

Date

Mark  / 24

Section A

Circle the letter of the correct answer. One mark each.

  1. 1What does print("Hello") do?1
    1. ANothing
    2. BSends Hello to a printer
    3. CStores Hello in a variable
    4. DDisplays Hello on the screen
  2. 2What symbol starts a comment in Python?1
    1. A#
    2. B//
    3. C/*
    4. D--
  3. 3Which error means you used a variable that does not exist?1
    1. ASyntaxError
    2. BValueError
    3. CTypeError
    4. DNameError
  4. 4What does print("Score", 10) display?1
    1. AAn error
    2. BScore, 10
    3. CScore 10
    4. DScore10
  5. 5What kind of error is a missing colon at the end of an if line?1
    1. AA name error
    2. BA syntax error
    3. CA runtime error
    4. DA logic error
  6. 6Which is the best comment?1
    1. A# skip the header row
    2. B# code
    3. C# this is a loop
    4. D# add one to i
  7. 7What causes a ValueError in int("hello")?1
    1. Ahello is too long
    2. BThe quotes are wrong
    3. Cint is spelled wrongly
    4. DThe text cannot be converted into a number
  8. 8Why should you run your code frequently?1
    1. APython requires it
    2. BIt makes the program faster
    3. CSo you know exactly which few lines caused a new error
    4. DIt saves the file
  9. 9What does the last line of an error message tell you?1
    1. AHow long the program ran
    2. BThe type of error and a description of the problem
    3. CThe name of the file
    4. DThe next line to write
  10. 10Which variable name is best?1
    1. Ax
    2. Btotal_score
    3. Ca1
    4. Dts

Section B

Answer in the space provided. The number of marks tells you how many separate points to make.

  1. 1StateState the purpose of a comment in a program.2
  2. 2ExplainExplain the difference between a syntax error and a runtime error, giving an example of each.4
  3. 3IdentifyA student writes print("Hello) and gets an error. Identify the error and correct it.2
  4. 4ExplainExplain why printing the value of a variable is a useful way to find errors in a program.3
  5. 5WriteWrite a program that displays your name and your favourite subject on two separate lines, with a comment explaining what it does.3

Mark scheme

Section A

1D2A3D4C5B6A7D8C9B10B

Section B

1 State the purpose of a comment in a program. 2

One mark for each of the following, to a maximum of 2.

  • A note for humans reading the code
  • Ignored by the computer when the program runs

Model answer. A comment is a note written in the code to explain something to a person reading it, such as why a particular approach was taken. It is completely ignored by Python when the program runs, so it has no effect on what the program does.

2 Explain the difference between a syntax error and a runtime error, giving an example of each. 4

One mark for each of the following, to a maximum of 4.

  • A syntax error breaks the rules of the language
  • So the program will not run at all
  • A runtime error occurs while the program is running
  • Gives valid examples such as a missing bracket and dividing by zero

Model answer. A syntax error is a mistake in the way the code is written, such as a missing closing bracket or a missing colon at the end of an if statement. Because the code does not follow the rules of the language, Python cannot interpret it at all and the program will not run, so the error appears before anything happens. A runtime error occurs in code that is perfectly valid but which fails while it is executing, for example dividing by zero or trying to convert the text hello into a number. The program starts normally and then crashes at the point the problem occurs.

3 A student writes print("Hello) and gets an error. Identify the error and correct it. 2

One mark for each of the following, to a maximum of 2.

  • The closing quotation mark is missing
  • Correct code is print("Hello")

Model answer. The string has an opening quotation mark but no closing one, so Python reaches the end of the line still expecting the text to continue and reports a syntax error. The corrected line is print("Hello") with a closing quotation mark before the closing bracket.

4 Explain why printing the value of a variable is a useful way to find errors in a program. 3

One mark for each of the following, to a maximum of 3.

  • It shows what the variable actually contains at that point
  • This may be different from what the programmer assumed
  • It narrows down which part of the program is wrong

Model answer. Printing a variable shows exactly what it holds at that moment in the program, which is frequently not what the programmer assumed it held. Many bugs come from a variable containing text when a number was expected, or holding a value from an earlier iteration, and these are invisible just by reading the code. By printing values at several points, the programmer can see where the value first becomes wrong, which narrows the problem down to a small section rather than the whole program.

5 Write a program that displays your name and your favourite subject on two separate lines, with a comment explaining what it does. 3

One mark for each of the following, to a maximum of 3.

  • Includes a comment
  • Uses print correctly with quotation marks
  • Produces output on two separate lines

Model answer. # Display some information about me print("My name is Aisha") print("My favourite subject is Computing") The comment on the first line explains the purpose of the program and is ignored when it runs. Each print statement outputs its text and then moves to a new line, so using two separate print statements produces two lines of output.