Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A program has eight lines. Line 5 has a missing comma and line 7 has a missing bracket, so neither can be translated. Every other line is correct, and line 4 outputs a number.
1 score = 7
2 bonus = 3
3 total = score + bonus
4 print(total)
5 print('Well done' total)
6 half = total / 2
7 print(half
8 print('End')A compiler translates the whole code at once, before executing it, produces an executable file, and gives an error report for the whole code. An interpreter translates and executes the code line by line and stops when it finds an error. An interpreter is mostly used when developing a program; a compiler translates the final program.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. The interpreter. It translates and runs lines 1 to 4. Line 4 outputs , because . At line 5 it finds the missing comma and stops. So lines are run, and it never reaches line 7.
Step 2. The compiler. It translates the whole code before running any of it. It reports errors, on lines 5 and 7. No executable file is made, so lines are run.
Answer: (a) lines, output . (b) errors, lines run.
Watch out. The interpreter reports one error at a time. After the programmer fixes line 5 and runs it again, it will stop at line 7. The compiler shows both at once.
Log in to join the discussion.
Loading…