Examples
Below are a couple of examples for how you should go about this assignment.
Example 1:โ
Setupโ
- Navigate to your repository in the command line.
- You can either use the
cd PATH_TO_FOLDER
command.- In my case the command was
cd /Users/wesreed/git/School/IT3049/Python-Basics
- Use the
pwd
command to Print Working Directory and confirm your location
- In my case the command was
- OR You could open VSCode integrated terminal window and it will open in the terminal already in the right path.
Installing the dependencies
pip install -r requirements.txt
Run the tests using
pytest
.
- Notice all the errors, our goal for this assignment is to resolve them all.
Getting Down to Businessโ
Open the project in Visual Studio Code (Not Visual Studio)
Let's try to solve a couple of those tests.
Open the file
numbers_1.py
. Particularly# parse_int: should convert strings to integer numbers
def parse_int (str):
return- Notice the function have an empty implementation. - We need to do something about that ๐ค
Consulting the Python documentation for built-in functions. The documentations shows usage examples, and specifies the parameters and return type of the function.
Key Takeaways:
# parse_int: should convert strings to integer numbers
def parse_int (str):
return int(str)- Don't forget to
return
something from the function.
- Don't forget to
Re-run the tests again and let's see if it passes
Commit your code
git commit -m "finished test parseInt"
.
Example 2:โ
- Well, no need for the setup steps here (you should already be in the directory)
- Open the file
lists_3.py
. Particularly at this function'''
IndexOf: you should be able to determine the location of an item in an list
Example:
arr = [1,2,3,5,6]
calling the function like
index_of(arr, 3) should return the index 2
'''
def index_of(arr, item):
return - The
index_of
method is supposed to return the index of a certain element in a list. You can learn more about Python Built-in method here - My implementation for this is as follows
def index_of(arr, item):
return arr.index(item) - Re-run the tests again and let's see if it passes
- Commit your code
git commit -m "finished test: IndexOf"
.
On to the next test .. Rinse ๐งผ and Repeat ๐