Activities

Copy the following into a new Python file:

import pdb

def calculate_total(price, quantity):
    total = price * quantity  # Line 3
    return total  # Line 4

def apply_discount(total, discount):
    return total - (total * discount)  # Line 6

def main():
    price = 100
    quantity = 5
    discount = 0.1  # 10% discount
    total = calculate_total(price, quantity)  # Line 10
    total_after_discount = apply_discount(total, discount)  # Line 11
    print(f"Total after discount: {total_after_discount}")  # Line 12

pdb.set_trace()  # Pause the program here

main()
  1. Breakpoint and Next (n)

    1. Run the above code. When the debugger starts running, type 'n' and press enter on each line until you are finished debugging.

    2. Describe what happened.

  2. Single Line Stepping (s)

    1. Run the above code. When the debugger starts running, type 's' and press enter on each line until you are finished debugging.

    2. Describe what happened.

Describe

  1. Compare the next (n) command with the step (s) command.

Compare

  1. Watch, whatis and print (p)

    1. Run the above code. When the debugger starts running, type 's' and press enter for 8 lines in a row.

    2. Then, type 'whatis total'

    3. Then, type 'p total'

    4. Describe what happened.

  2. Compare whatis and print (p) commands.

Submit when Finished

Last updated