Assignment 1
Assignment
In class, you were given a search_for function that looked like this:
def search_for(item, list_to_search_in):
result = item in list_to_search_in
return result
The in operator here does most of the heavy lifting in this code, but how does it work? To help us think about what is going on here, your assignment is to rewrite this function so that it uses a loop and an if statement instead of the list-contains (i.e., in) operator.
Note that you can still use the in operator if setting up a for loop, just don’t directly use it to check if the item is in the list.
Grading
This is a 4-point assignment. See the rubric from the syllabus.
How to turn it in
- Put your code in a file called
simple_search.pyand make sure you named the functionsearch_for. - Make sure your code works when you run it in VS Code when you run it in script mode.
- After you’ve tested it, log into https://codepost.io/ and submit
simple_search.pyto Assignment 1: search_for .
Note: I wrote a simple test script that calls your function with different inputs and attempts to give you some feedback about how it did - this will be part of how your code is graded. You can resubmit as many times as you like until the due date. I will also look at your code to make sure you’re using loops and if statements properly.