Development Environments
Integrated Development Environments: Edit, Run, and Inspect
Writing a program involves more than entering instructions. You also need to save the right file, execute it with suitable software, inspect its output, and investigate unexpected behaviour. An integrated development environment, or IDE, brings tools for these tasks into one application. Thonny is one example used for learning Python. Understanding the tools matters more than memorizing where a particular version places its buttons.
Tools in one workspace
An IDE connects several tools, but each has a different job. Its editor works with source code. For Python, an interpreter executes those instructions. A debugger lets you pause execution and inspect program state: the values currently stored in variables and the point execution has reached.
Tool | Main purpose | What it does not establish |
|---|---|---|
Editor | Write and revise source code | That the program produces the intended result |
Interpreter | Execute Python instructions | That the chosen calculation is appropriate |
Shell or output area | Display printed results and execution messages | That every visible message belongs to the latest run |
Debugger | Pause execution and inspect values | That every possible input has been tested |
Syntax highlighting makes code easier to read. It does not prove that the code is valid or correct. Even a program that runs without an error message can calculate the wrong answer.
What happens when you run
A dependable starting habit is to save your source, confirm which file will run, and check the selected interpreter. Some IDEs save automatically or can execute unsaved editor contents; others require an explicit save. Knowing the behaviour of your IDE prevents confusion about which version you tested.
The selected runtime environment also matters. A program may rely on a library that is available to one Python interpreter but unavailable to another. Choosing the intended source file and choosing the intended interpreter are separate decisions.
Read execution messages as evidence. An error message identifies a problem encountered during execution or preparation for execution; it does not necessarily identify the original cause. Likewise, output left from an earlier run cannot establish what the current run has done.
Debugging deliberately
A breakpoint is a selected location where the debugger pauses execution. In a typical line debugger, pausing at a breakpoint means execution has reached that line but has not yet executed it. Check your debugger's highlighted-line convention before interpreting values.
Use the variable inspector to examine the inputs to a suspicious statement. Then use Step Over to execute that statement without following its internal function calls line by line. Inspect the resulting values before continuing. A line number is a location, not a count of how many times the line has executed.
For a chosen test case, your basic check is:
Example: A program should print Welcome but prints Ready. Seeing Ready in the Shell identifies an observable mismatch. Pausing before the relevant print statement helps you check which instruction the current run is about to execute.
What to remember
- An IDE combines tools with distinct responsibilities.
- Check both the source file and the selected interpreter.
- Use breakpoints and stepping to connect instructions with changing values.
- Retest the saved correction in a fresh run.
Example: Investigating a craft-stall total
Example: You are using Thonny to prepare a small Python program for a craft stall. Each item costs 8 dollars, and a customer buys 5 items. The intended total is the item price multiplied by the quantity. Your saved file, stall_total.py, contains:
item_price = 8
quantity = 5
total = item_price + quantity
print(totalFor this example, a debugger pauses before executing its highlighted line, and Step Over executes that line before pausing at the next one. The selected Python interpreter is suitable for this program, which needs no additional libraries.
Part a: Make the program executable
The IDE reports a syntax error at the incomplete print statement. Correct that statement and describe what you should save before testing again.
The opening parenthesis in the print statement has no closing partner. Complete the statement as follows:
print(total)Save the correction in stall_total.py and confirm that Run selects that file. Correcting the syntax allows execution to proceed, but it does not check whether the calculation matches the intended purchase total.
The corrected final statement is print(total), saved in stall_total.py.
Part b: Inspect the calculation
After correcting the print statement, set a breakpoint, a selected location where the debugger pauses, on total = item_price + quantity. Start debugging. What values should the inspector show before this assignment, and what total will one press of Step Over produce?
The first two assignments execute before the breakpoint is reached. The inspector should show item_price as ________ dollars per item and quantity as ________ items. The highlighted total assignment has not executed yet.
One press of Step Over executes the addition written in the source:
The program treats this numeric result as a dollar total, so the inspector shows 13 dollars. It then pauses before the print statement. This is evidence that Python executed the addition as written; it is not evidence that addition is the appropriate purchase calculation.
The operands also expose the mistake: adding a price per item to an item count does not calculate a purchase total. The intended operation must combine them by multiplication.
Part c: Repair and verify the source
Correct the calculation in the editor. Explain how to verify the repair and state the output expected from a fresh run.
Stop the debug run and replace the addition with multiplication:
total = item_price * quantitySave stall_total.py. Restart the saved program using the same purchase values, rather than assigning a replacement total interactively in the Shell. A temporary variable change would not repair the source.
Calculate the expected result independently:
The corrected program should print 40, representing 40 dollars. Compare that expectation with the new output from the fresh run. Agreement verifies this purchase case; other quantities would require their own tests.
A student runs the file stall.py in their development environment, and the Shell shows this traceback instead of the expected total:
Traceback (most recent call last):
File "stall.py", line 9
total = add_items(prices)
File "stall.py", line 4, in add_items
subtotal = subtotal + p
TypeError: unsupported operand type(s) for +: 'int' and 'str'Fill in each blank with a single number or word. The statement that actually failed is on line of the file. The statement in the main program that called the failing function is on line . The kind of exception that stopped the program is a .
You save receipt_copy.py, which contains print(18). A separate file, receipt.py, contains print(12). Both files are open in an IDE. When you press Run, the current execution message names receipt.py, and the new output is 12. Which action directly addresses the mismatch between the intended file and the executed file?