13.3. Week 3 Lab

Material Covered

Python modules and debugging (Chapter 3)

Tip

When debugging a program, whether it be your own or someone else’s, it’s best to understand what the program is trying to do first. Read through the code and comments before editing the program. Also, when errors occur, it helps to start from the line number of the error and work your way backwards.

13.3.1. Level 1

The program below contains multiple errors. Your objective is to debug the program, and match the expected output (see below the code). You can run the code to see error messages.

Tip

You do not need to delete any lines of code, only edit/add.

For the following inputs:

loan = 5000

time = 12

rate = 6.25

The program should print:

> Your annual compound interest is: 5349

13.3.2. Level 2

The program below runs but contains multiple semantic (logic) and programmer errors.

Your objective is to debug the program, and match the expected output (see below the code).

Tip

There are three errors on three separate lines

For the following inputs:

income_2020 = 10000

income_2021 = 10000

The program should print:

> Your tax rate for 2020 and 2021 was 24.0 percent

13.3.3. Level 3

The following is a screenshot of turtle output. The program uses three turtles: 2 white and 1 red.

../_images/turtle_triangles1.png

Tip

The windows size is 400 pixels by 400 pixels (default size)

You must recreate the output using the following guidelines:

  • The white turtles have pen size is 1, while the red has pen size 2

  • The red turtle draws last

  • The red turtle draws a singular line at a random angle from 0-360 and a random length from 0 to 200

You have attempted of activities on this page