Chapter 1 Lec 3
Chapter 1 Lec 3
Topic: Advanced Flowchart Creation, Translating Flowcharts into Python Code, Debugging and Testing
Programs
Overview: As programs become more sophisticated, flowcharts must also evolve to accurately represent
the logic and flow of more complex algorithms.
Example Scenarios:
o Handling multiple decision points (e.g., a program that categorizes input based on several
criteria).
o Incorporating loops and iterations (e.g., a program that processes data in a list).
Multi-Level Flowcharts:
o Introduce the concept of breaking down large problems into smaller, manageable sub-tasks.
o Use sub-processes or sub-routines in flowcharts to simplify complex problems.
Example Flowchart:
o Design a flowchart for a program that calculates the factorial of a number.
o Include decision points for input validation and iterative loops to compute the factorial.
Flowcharts as Blueprints:
o Emphasize that flowcharts serve as a visual representation of the algorithm, which can be
directly translated into code.
o Each symbol in the flowchart corresponds to a specific construct in Python (e.g., decisions
become if statements, loops become for or while loops).
B. Step-by-Step Translation
Example Flowchart:
o Use the previously created factorial flowchart.
o Translate the flowchart into Python code, highlighting how each step of the flowchart maps to
lines of code.
Writing the Python Code:
Why Test?:
o Ensure that the program works as expected in different scenarios.
o Catch errors early and improve the reliability of the program.
Types of Testing:
o Unit Testing: Testing individual components of a program.
o Integration Testing: Ensuring that different parts of the program work together correctly.
o Boundary Testing: Checking how the program handles edge cases.
5 120
0 1
-3 Error message
Input Expected Output
10 3,628,800
Running Tests:
o Implement the test plan by running the program with each input and comparing the output to the
expected results.
C. Debugging Techniques
Identifying Bugs:
o Use error messages and tracebacks to locate issues in the code.
o Test each part of the program separately to isolate the problem.
Common Debugging Strategies:
o Print Statements: Insert print() statements to monitor variable values and program flow.
o Using a Debugger: Step through the code line by line using an IDE's debugger to observe the
program's behavior.
o Refactoring: Simplify or rewrite problematic sections of code to make them easier to understand
and debug.
Example Debugging Session:
o Walk through a scenario where a student’s factorial program produces incorrect results.
o Demonstrate how to apply debugging techniques to find and fix the error.
-The End-