Jan-10-2024, 08:39 AM
(This post was last modified: Jan-10-2024, 03:19 PM by deanhystad.)
Can you replace your code with below code:
class LinearSearch: def __init__(self, entered_list=None, item=None): self.entered_list = entered_list self.item = item def seek(self, item): for index, element in enumerate(self.entered_list): if element == item: return index return -1 # Return -1 if the item is not found in the list def __str__(self): result = self.seek(self.item) if result != -1: return f"Item found at index {result}" else: return "Not Present"Thanks
deanhystad write Jan-10-2024, 03:19 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.