MAKE IT YOURS

A world for every learner

Choose a grade to discover its colours and creative world.

Grade 12 Tracing Code (Python) Worksheet with Answers

Grade 12 (US) · Year 13 (UK) · Class 12 (India) · Computer Science

Unit 2: ProgrammingTracing Programs

Reading short Python programs with variables, if/else and loops and working out what they print. This free high school worksheet has 12 questions and a full answer key. Print it or save it as a PDF — every answer is checked by code, not guessed.

  • Answer keys checked by code
  • No ads, ever
  • No student accounts needed
  • Safety & privacy
Practice Sheetaethelsystems.com

Tracing Code (Python)

Grade 12 · Computer Science

Score___ / 12

Name

Class

Date

Learning goal: Tracing Programs

Directions: Read each question carefully and write your answer on the line. Use the diagram to help you.

RememberReading Python

x = 5store 5 in xrange(1, 4)1, 2, 3(stops before 4)// and %7 // 2 = 37 % 2 = 1Indentindented linesbelong to the loop/if
  1. 1

    What does this program print?

    1x = 202if x > 10:3print("big")4elif x == 10:5print("equal")6else:7print("small")
  2. 2

    What does this program print?

    1word = "ALGORITHM"2print(word[0] + word[-1])
  3. 3

    What does this program print?

    1word = "COMPUTER"2print(word[2] + word[-1])
  4. 4

    What does this program print?

    1x = 102if x > 14:3print("big")4elif x == 14:5print("equal")6else:7print("small")
  5. 5

    What does this program print?

    1word = "KEYBOARD"2print(word[2] + word[-1])
  6. 6

    What does this program print?

    1word = "COMPUTER"2print(word[3] + word[-1])
  7. 7

    What does this program print?

    1word = "NETWORK"2print(word[3] + word[-1])
  8. 8

    What does this program print?

    1total = 02for i in range(1, 5):3total = total + i * 24print(total)
  9. 9

    What does this program print?

    1total = 02for i in range(1, 6):3total = total + i * 14print(total)
  10. 10

    What does this program print?

    1total = 02for i in range(1, 6):3total = total + i * 24print(total)
  11. 11

    What does this program print?

    1word = "ALGORITHM"2print(word[2] + word[-1])
  12. 12

    What does this program print?

    1total = 02for i in range(1, 8):3total = total + i * 14print(total)

★ Challenge corner for fast finishers

6 computers each connect directly to every other computer with one cable. How many cables are needed?

How did I do?

Teacher's comments

Free printable worksheets with answer keys · aethelsystems.com/worksheets/computer/12/code_tracing

Answer key (click to show)
  1. 1.big
  2. 2.AM
  3. 3.MR
  4. 4.small
  5. 5.YD
  6. 6.PR
  7. 7.WK
  8. 8.20
  9. 9.15
  10. 10.30
  11. 11.GM
  12. 12.28
  13. ★15 (challenge corner)

Need another Tracing Code (Python) worksheet?

Generate unlimited fresh versions at easy, medium or hard difficulty, each with its own answer key. Free during our launch — no card needed.

Create a free account

How to use this worksheet

  • Use it for revision before a test, as homework, or as a timed practice set.
  • Students can self-mark with the answer key and note which question types they got wrong.
  • Generate several versions of the same topic for spaced practice in the weeks before an exam.

Can't find what you need? Tell us which worksheet to make next.

Frequently asked questions

Does this Grade 12 Tracing Code (Python) worksheet come with answers?

Yes. The full answer key is on this page, and it prints on its own page after the questions. Every answer is calculated or checked by code rather than written by an AI model, so the key is always correct.

How do I print it or save it as a PDF?

Click "Download PDF" to save a ready-to-print PDF with the answer key on the last page, or click "Print" to send the worksheet and answer key straight to your printer.

Can I get a different Tracing Code (Python) worksheet?

Yes. Create a free account to generate as many fresh Grade 12 Tracing Code (Python) worksheets as you like, at easy, medium or hard difficulty, each with its own answer key.

Is this worksheet free?

Yes. This worksheet is free to print, and Practice Sheet is free to use during our launch with no card needed.