IDE function: code editor

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

IDE function: code editor

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Where in an IDE do you type and edit your source code?
A The code editor
B The translator
2. Which statement about line numbers in a code editor is correct?
A They are part of the program and are run by the computer
B They help you find and refer to a line, for example when an error message names line 12
3. What does syntax highlighting do in a code editor?
A Fixes syntax errors automatically
B Shows keywords in different colours
4. Which of these has syntax highlighting and line numbers as standard?
A A code editor in an IDE
B A plain text editor
5. A student types print in blue and a string in red. Which feature is this?
A Syntax highlighting in the code editor
B Running the program in the run-time environment

Match the Pairs

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

Left columnRight column
1code editor AThis describes a translator (compiler or interpreter), not the code editor. The code editor is where you type and edit the source code.
2syntax highlighting B1 name = input("Name: ") 2 print(name)
3A code editor shows line numbers down the side so you can find the line an error message mentions CThe part of an IDE where the programmer types and edits source code
4A code editor uses syntax highlighting, so keywords such as print and if appear in a different colour from the rest of the code Dif age >= 16: # 'if' shown in colour
5A code editor is the part of an IDE that translates source code into machine code. EA plain text editor does not normally give line numbers or syntax highlighting. These features are what make a code editor different.
6A plain text editor like Notepad gives line numbers and colour-coded keywords just like a code editor in an IDE. FColour-coding keywords, strings and numbers in the code editor so they are easier to spot

Definitions

code editor

Fill in the Blanks

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

1.
# The code editor colours keywords _____("Score:", 10) # print is shown in a keyword colour
2.
___ i in range(3): print(i)
3.
score = 60 if score _ 50: print("Pass")
4.
_ This comment is shown in a new colour
5.
___ greet(name): print("Hi", name)

Spot the Error

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

Question 1
A name = "code editor"
B has_line_numbers = True
C has_highlighting = True
D if has_line_numbers
E print("Editor: " + name)
Question 2
A keywords = ["if", "for", "while"]
B for word in keywords:
C print("Blue:", word
Question 3
A define show_line(num, text):
B print(num, text)
C show_line(1, "print('Hi')")
Question 4
A lines = 3
B count = 0
C while count < lines:
D count + 1 = count
E print("Line", count)
Question 5
A editor_type = "code editor
B if editor_type == "code editor":
C print("Line numbers shown")

Answer Key

IDE function: code editor
Section A: Quick Questions
Q1
A — The code editor
Q2
B — They help you find and refer to a line, for example when an error message names line 12
Q3
B — Shows keywords in different colours
Q4
A — A code editor in an IDE
Q5
A — Syntax highlighting in the code editor
Section B: Match the Pairs
Q1
code editor → The part of an IDE where the programmer types and edits source code
Q2
syntax highlighting → Colour-coding keywords, strings and numbers in the code editor so they are easier to spot
Q3
A code editor shows line numbers down the side so you can find the line an error message mentions → 1 name = input("Name: ") 2 print(name)
Q4
A code editor uses syntax highlighting, so keywords such as print and if appear in a different colour from the rest of the code → if age >= 16: # 'if' shown in colour
Q5
A code editor is the part of an IDE that translates source code into machine code. → This describes a translator (compiler or interpreter), not the code editor. The code editor is where you type and edit the source code.
Q6
A plain text editor like Notepad gives line numbers and colour-coded keywords just like a code editor in an IDE. → A plain text editor does not normally give line numbers or syntax highlighting. These features are what make a code editor different.
Section C: Definitions
Q1
code editor — The part of an IDE where you type and edit source code. It shows line numbers and syntax highlighting (colour-coded keywords), which a plain text editor does not.
Section D: Fill in the Blanks
Q1
# The code editor colours keywords print("Score:", 10) # print is shown in a keyword colour
Q2
for i in range(3): print(i)
Q3
score = 60 if score > 50: print("Pass")
Q4
# This comment is shown in a new colour
Q5
def greet(name): print("Hi", name)
Section E: Spot the Error
Q1
D — An if statement must end with a colon. Without it the code has a syntax error. It should be: if has_line_numbers:
Q2
C — The closing bracket is missing from the print call. A code editor can help you spot this, but the fix is: print("Blue:", word)
Q3
A — Python uses the keyword def, not define. A code editor with syntax highlighting would not colour define as a keyword, which is a clue that it is wrong.
Q4
D — The variable being assigned to must be on the left of the = sign. It should be: count = count + 1
Q5
A — The string is missing its closing quote. A code editor with syntax highlighting would colour the rest of the line as text, showing the mistake. It should end with ".