Comments with // (8.1a)

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Comments with // (8.1a)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line is a correct comment in Cambridge pseudocode?
A Store the player's score //
B // Store the player's score
2. What happens to the text after // when the program runs?
A It is run as code
B It is ignored
3. Which program prints the same output as the other three when the comment is removed? Pick the statement that is true about comments.
A Adding a comment does not change what the program does
B Adding a comment changes the value stored in the variable
4. Which line puts a short comment at the end of a line of code?
A Total ← Price * 3 // cost of 3 items
B Total ← Price * 3 cost of 3 items
5. A comment needs to explain code that runs over two lines. Which is correct?
A // Calculate the total cost // including the delivery fee
B // Calculate the total cost including the delivery fee

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1// Calculate the area AThe second line of the comment is missing //, so it would be treated as code and cause an error.
2Total ← Price * Qty // cost of items BA statement followed by an end-of-line comment: the assignment runs but the comment is ignored
3A comment that spans several lines needs // at the start of every line CA comment on its own line that explains the code below it and is ignored when the program runs
4Adding a comment does not change what the program does, so the program still outputs 10 DA single slash does not start a comment. It must be two slashes //, otherwise the text is treated as code and causes an error.
5Score ← 0 / set score to zero E// Program to find the average // Input three marks and output the mean
6// Ask the user for a name and store it in Name INPUT Name FX ← 10 // set X to ten OUTPUT X

Definitions

//

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
__ Set the starting score Score ← 0
2.
Total ← Price * Quantity __ cost of items
3.
// Calculate the area of a rectangle __ Width and Height are in cm Area ← Width * Height
4.
______ Total // show the final total
5.
Lives _ 3 // player starts with 3 lives

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A // Store the player's score
B DECLARE Score : INTEGER
C Score ← 0 # start at zero
D OUTPUT Score
Question 2
A / Ask for the user's name
B DECLARE Name : STRING
C INPUT Name
D OUTPUT "Hello ", Name
Question 3
A CONSTANT Pi ← 3.142
B INPUT Radius
C // Work out the circle area
D // Area ← Pi * Radius ^ 2
E OUTPUT Area
Question 4
A DECLARE Lives : INTEGER
B Lives ← // starting lives 3
C OUTPUT Lives
Question 5
A // Program: temperature check
B // Written for Year 10
C Converts C to F
D INPUT Celsius
E OUTPUT Celsius * 9 / 5 + 32

Answer Key

Comments with // (8.1a)
Section A: Quick Questions
Q1
B — // Store the player's score
Q2
B — It is ignored
Q3
A — Adding a comment does not change what the program does
Q4
A — Total ← Price * 3 // cost of 3 items
Q5
A — // Calculate the total cost // including the delivery fee
Section B: Match the Pairs
Q1
// Calculate the area → A comment on its own line that explains the code below it and is ignored when the program runs
Q2
Total ← Price * Qty // cost of items → A statement followed by an end-of-line comment: the assignment runs but the comment is ignored
Q3
A comment that spans several lines needs // at the start of every line → // Program to find the average // Input three marks and output the mean
Q4
Adding a comment does not change what the program does, so the program still outputs 10 → X ← 10 // set X to ten OUTPUT X
Q5
Score ← 0 / set score to zero → A single slash does not start a comment. It must be two slashes //, otherwise the text is treated as code and causes an error.
Q6
// Ask the user for a name and store it in Name INPUT Name → The second line of the comment is missing //, so it would be treated as code and cause an error.
Section C: Definitions
Q1
// — Starts a comment. Everything after // on that line explains the code to people and is ignored when the program runs, so it never changes what the program does.
Section D: Fill in the Blanks
Q1
// Set the starting score Score ← 0
Q2
Total ← Price * Quantity // cost of items
Q3
// Calculate the area of a rectangle // Width and Height are in cm Area ← Width * Height
Q4
OUTPUT Total // show the final total
Q5
Lives ← 3 // player starts with 3 lives
Section E: Spot the Error
Q1
C — Cambridge pseudocode comments start with //, not #. The line should be Score ← 0 // start at zero.
Q2
A — A comment needs two forward slashes. A single / is not a comment, so the words would be read as code. It should be // Ask for the user's name.
Q3
D — The // turned the calculation into a comment, so it never runs and Area has no value. The calculation should be Area ← Pi * Radius ^ 2 with no // before it. The comment belongs on its own line above.
Q4
B — Everything after // is ignored, so the 3 is now part of the comment and the assignment has no value. The comment must go after the code: Lives ← 3 // starting lives.
Q5
C — In a multi-line comment, every line must start with //. Without it, this line is treated as code. It should be // Converts C to F.