Lab 2 / Flowcharts to Python

This lab asks you to write Python code based on a provided flowchart that runs a binary search algorithm to find an item in an array.

Learning objectives

  • Interpret branching and looping logic in flowcharts

  • Use condition-controlled loops (WHILE) and exception handling

Flowchart

Instructions

  1. Analyse the file binary_search_flowchart.png and

  2. Do a dry run of the algorithm and create trace tables for the following test cases:

  • [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

  • [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]

  • [G, H, I, J, K, L, M, N, O, P]

  • [blue, brown, green, orange, pink, purple, red, white, yellow]

  1. Write a Python program that implements the logic described in the flowchart.

  2. Test your program with the test cases provided above.

Last updated

Was this helpful?