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()
Breakpoint and Next (n)
Run the above code. When the debugger starts running, type 'n' and press enter on each line until you are finished debugging.
Describe what happened.
Single Line Stepping (s)
Run the above code. When the debugger starts running, type 's' and press enter on each line until you are finished debugging.
Describe what happened.
Compare the next (n) command with the step (s) command.
Watch, whatis and print (p)
Run the above code. When the debugger starts running, type 's' and press enter for 8 lines in a row.
Then, type 'whatis total'
Then, type 'p total'
Describe what happened.
Compare whatis and print (p) commands.
Last updated