# Dry Run Testing & Trace Tables

#### Learning Objectives

You have just completed a piece of code but when you run it, it does not behave as expected.

One way to check and troubleshoot your code is to perform a dry run using a trace table.

Trace tables are used by programmers to track the values of variables as they change throughout the program. This is useful when a program is not producing the desired result.

#### Context / Starter activity

A primary teacher likes to start her maths lesson by displaying a number sequence maths challenge on the board. Here are the last three challenges she has used with her class. Can you solve these?

Number Sequence #1: Number Sequence #2: Number Sequence #3: The primary teacher decided to create some Python script to help them create similar number sequences.

Here is the pseudo-code for her first script:

```number = 3
PRINT number
FOR  i  from 1 to 3:
number = number + 5
PRINT number
PRINT "?"```

To make sure her script is working she decided to complete a dry run test using a trace table. See animation below: View the complete trace table.

#### Challenge #1

Step 1: Complete the trace table for the following script:

```number = 5
PRINT number
FOR  i  from 1 to 3:
number = number + i
PRINT number
PRINT "?"```

Step 2: Implement this code using a high level programming language (e.g. Python) and compare your trace table with your actual output of your program.

#### Challenge #2

Step 1: Complete the trace table for the following script:

```number1 = 2
number2 = 5
PRINT number1
PRINT number2
FOR  i  from 1 to 4:
number1 = number1 + number2
PRINT number1
number2 = number1
PRINT "?"```

Step 2: Implement this code using a high level programming language (e.g. Python) and compare your trace table with your actual output of your program.

#### Challenge #3

Think of your own number sequences. Write the pseudo-code, the trace table and implement them using a high level programming language (e.g. Python).

Did you like this challenge?

Click on a star to rate it!

Average rating 2.7 / 5. Vote count: 18

No votes so far! Be the first to rate this post.

As you found this challenge interesting...