Skip to main content
Activity (Hands-On)Grades 11 - 12

Python Script Analysis

A photograph from behind a boy working at a laptop analyzing lines of computer code.Students explore Python code

Working in small groups, students complete and run functioning Python codes. They begin by determining the missing commands in a sample piece of Python code that doubles all the elements of a given input and sums the resulting values. Then students modify more advanced Python code, which numerically computes the slope of a tangent line by finding the slopes of progressively closer secant lines; to this code they add explanatory comments to describe the function of each line of code. This requires students to understand the logic employed in the Python code. Finally, students make modifications to the code in order to find the slopes of tangents to a variety of functions.

Engineers of all fields analyze systems, whether the electrical systems in automobiles, the chemical systems in petroleum extraction, river management systems, or the mechanical systems in airplanes. Software engineers must perform code analysis as part of the debugging process. Since computer code rarely performs correctly the first time it is written, analysis skills to determine the function of the code enable engineers to locate and solve any problems with the code. This activity provides a canvas for students to practice analysis of this type of system. They examine Python programming language code to determine what it does and make modifications based on their analyses, similar to what software engineers do daily to problem solve.

After this activity, students should be able to:

  • Use the Python programming language to investigate slopes of tangents.
  • Analyze computer code to determine its function.
  • Make changes to computer code based on their analyses.

More Like This