3.1. The CodeLens Tool

In addition to activecode, you can also execute Python code with the assistance of a unique visualization tool. This tool, known as codelens, allows you to control the step by step execution of a program. It also lets you see the values of all variables as they are created and modified. The following example shows codelens in action on the same simple program as we saw above. Remember that in activecode, the source code executes from beginning to end and you can see the final result. In codelens you can see and control the step by step progress. Try clicking on the forward button below.

Activity: CodeLens 3.1.1 (over_codelens1)

Note that you can control the step by step execution and you can even move forward and backward thru the statements as they execute.

The following example shows a more sophisticated program using Python lists. The codelens tool draws very useful pictures as the statements are being executed. These pictures, called reference diagrams, are very helpful as you learn about the more complex aspects of Python.

Activity: CodeLens 3.1.2 (secondexample)

3.2. CodeLens Predictions

Here is a different sort of CodeLens visualization. Some CodeLens blocks can have questions embedded in them that will ask you a question about the value of a variable, or which line will be the next line to execute. This example asks you to keep track of the tot variable as you step through the loop.

Activity: CodeLens 3.2.1 (codelens_question)

Here’s another example that asks the student to predict which line will be the next line executed.

Activity: CodeLens 3.2.2 (codelens_question_line)

You have attempted of activities on this page