Imagine you want to translate a book from one language to another. Which of the following best describes how a compiler and an interpreter work?
Think about when the translation happens: all at once or bit by bit?
A compiler translates the entire program into machine code before running it, like translating a whole book before reading. An interpreter translates and runs the program line by line, like translating sentence by sentence while reading.
Consider this simple program interpreted line by line. What will be printed?
x = 5 print(x) x = x + 3 print(x)
Follow the program line by line and note the value of x at each print.
The interpreter runs line by line: first x is 5, so it prints 5. Then x becomes 8, so it prints 8.
Two programs do the same task. One is compiled, the other interpreted. Which runs faster and why?
Think about when the translation happens and how that affects speed.
Compiled programs run faster because the entire code is translated into machine code before execution, so the computer runs it directly. Interpreted programs translate code line by line during execution, which adds overhead and slows it down.
Look at the flowchart below describing how a program runs. Which step is the compilation step?

The compiler is the tool that translates source code into machine code.
The compilation step is done by the compiler, which takes source code and produces machine code that the computer can execute.
Some programming languages use both compilation and interpretation. Why would this be done?
Think about the benefits of each method and how they might complement each other.
Languages like Java compile code into an intermediate form (bytecode) for speed, then interpret or just-in-time compile it for flexibility and platform independence.