Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

erratum: chapter 3 #5

Closed
khosrogh opened this issue Dec 12, 2021 · 1 comment
Closed

erratum: chapter 3 #5

khosrogh opened this issue Dec 12, 2021 · 1 comment

Comments

@khosrogh
Copy link

  • Page 69: in the code for linear search, an indentation is needed in the else statement part. It works well for items that are in the searched list, but for items that aren't in the searched list, it goes to an infinite loop and needs to interrupt the kernel. The code on page 69 is:
def LinearSearch(list, item):
    index = 0
    found = False
# Match the value with each data element
    while index < len(list) and found is False:
        if list[index] == item:
            found = True
    else:
        index = index + 1
    return found

The code above should be indented like below:

def LinearSearch(list, item):
    index = 0
    found = False
# Match the value with each data element
    while index < len(list) and found is False:
        if list[index] == item:
            found = True
        else:
            index = index + 1
    return found

Codes in here are OK.

@rajat-packt
Copy link
Contributor

We have update the readme with the correct code and so we'll be closing this issue.
Nice work, we appreciate the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants