Activities
Last updated
Last updated
Copy the following into a new Python file:
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 = 10 #
total = calculate_total(price, quantity) # Line 10
total_after_discount = apply_discount(total) # Line 11
print(f"Total after discount: {total_after_discount}") # Line 12
main()
Set Up Debugging Mode
Open the Run and Debug panel (Ctrl + Shift + D
).
Click "Run and Debug" and choose "Python File".
Add Breakpoints
Click to the left of the line numbers to set breakpoints at:
Line 3 (where total
is calculated)
Line 6 (where discount is applied)
Line 10 (when calculate_total
is called)
Line 11 (when apply_discount
is called)
Run the Debugger
Press F5
to start debugging.
Use F10
to step over each line and inspect variables in the Variables panel.
Use the Debug Console to check variable values.
Identify the mistakes, correct them, and rerun the program to verify your fix.