<filename>src/Eighth Chapter/Example1.py
import sys


def find(strng, ch):
    """
      Find and return the index of ch in strng.
      Return -1 if ch does not occur in strng.
    """
    ix = 0
    while ix < len(strng):
        if strng[ix] == ch:
            return ix
        ix += 1
    return -1


def find2(strng, ch, start):
    ix = start
    while ix < len(strng):
        if strng[ix] == ch:
            return ix
        ix += 1
    return -1


def test(did_pass):
    """  Print the result of a test.  """
    linenum = sys._getframe(1).f_lineno  # Get the caller's line number.
    if did_pass:
        msg = "Test at line {0} ok.".format(linenum)
    else:
        msg = ("Test at line {0} FAILED.".format(linenum))
    print(msg)


def test_suite():
    """ Run the suite of tests for code in this module (this file).
    """
    test(find("Compsci", "p") == 3)
    test(find("Compsci", "C") == 0)
    test(find("Compsci", "i") == 6)
    test(find("Compsci", "x") == -1)
    test(find2("banana", "a", 2) == 3)


test_suite()  # Here is the call to run the tests

<filename>src/Eighth Chapter/Example1.py
import sys


def find(strng, ch):
    """
      Find and return the index of ch in strng.
      Return -1 if ch does not occur in strng.
    """
    ix = 0
    while ix < len(strng):
        if strng[ix] == ch:
            return ix
        ix += 1
    return -1


def find2(strng, ch, start):
    ix = start
    while ix < len(strng):
        if strng[ix] == ch:
            return ix
        ix += 1
    return -1


def test(did_pass):
    """  Print the result of a test.  """
    linenum = sys._getframe(1).f_lineno  # Get the caller's line number.
    if did_pass:
        msg = "Test at line {0} ok.".format(linenum)
    else:
        msg = ("Test at line {0} FAILED.".format(linenum))
    print(msg)


def test_suite():
    """ Run the suite of tests for code in this module (this file).
    """
    test(find("Compsci", "p") == 3)
    test(find("Compsci", "C") == 0)
    test(find("Compsci", "i") == 6)
    test(find("Compsci", "x") == -1)
    test(find2("banana", "a", 2) == 3)


test_suite()  # Here is the call to run the tests

Find and return the index of ch in strng.       Return -1 if ch does not occur in strng. Print the result of a test. # Get the caller's line number. Run the suite of tests for code in this module (this file). # Here is the call to run the tests