Python Datatypes (a.k.a. "Groceries") Exercise
Further Exploration Challenges
If you were able to implement the basic requirements with relative ease, or if you are interested in a challenge, consider expanding the scope to include one or more of the challenges below.
Automated Tests
Prerequisites: The
pytest
Package
Before we test some of the program's logic, we need to abstract that logic into one or more custom functions (e.g. to_usd()
) which we can test in isolation. And we'll need to update the organizational structure of our script to include the infamous if __name__ == "__main__"
convention, to prevent the rest of the script's functionality from being executed when we attempt to import and test the to_usd()
function in isolation.
After making these organizational adjustments to your "groceries.py" file, add another file called "groceries_test.py" and place inside the following contents:
Then use the pytest
package to run the test:
If tests fail, update the logic of the to_usd()
function in the "groceries.py" file until the tests pass.
Nice, you're testing like a Pro!
Last updated