This scenario should encompass all of the topics provided in the module. Now that you’ve delved into creating a new class in Python it is now time to practice this concept.
You are tasked with building two different classes to aid with representing and modeling a bookstore. First will be a book object to allow for reading an online book and the second will be a coffee object as another object carried by the store. Both objects will have several attributes and functions to be called.
Before we begin coding, let's complete the initial setup for this lesson:
- Part 1: Fork and Clone- For this lesson, you will need the previously linked GitHub Repo:
- Go to the provided GitHub repository link.
- Fork the repository to your GitHub account.
- Clone the forked repository to your local machine.
- Part 2: Open and Run File
- Open the project in VSCode.
- Run
pipenv install
to install all necessary dependencies. - Run
pipenv shell
to enter the virtual environment.
This lab is test-driven. You will write your code in lib/book.py
and
lib/coffee.py
. Run the tests and work your way through the test errors one by
one until you get everything passing.
You're also encouraged to look at the test files to see what the tests are expecting to be able to do with your classes. These tests won't force you to use everything that you've learned in this module- feel free to add any features that might be useful!
Note that there are separate test files for the two classes inside the testing
folder. If you'd like to run the tests separately for the two classes, you can
specify which test file to run:
$ pytest -x testing/book_test.py
or:
$ pytest -x testing/coffee_test.py
Remember that the optional -x
flag makes your tests stop after the first
failure - this setting is ideal for test-driven development!
Build a model for a book and a coffee
As a user, one should be able to:
- Build a book object
- Build a coffee object
- Call to turn a book page
- Call to tip for the coffee
Book
- Attributes:
- title
- page_Count
- Methods:
- turn_page() Coffee
- Attributes:
- size
- price
- Methods:
- tip()
-
Create Feature Branch
-
Create Book class:
- init:
- title
- Require user to input
- page_count
- Require user to input
- title
- init:
-
Properties:
- page_count:
- Ensure it is an integer
- if not print “page_count must be an integer”
- page_count:
-
Methods:
- turn_page():
- Will print “Flipping the page...wow, you read fast!”
- turn_page():
- init:
- size
- Require user to input
- price
- Require user to input
- size
- Properties:
- Size
- Ensure size is either Small, Medium, or Large
- If not print “size must be Small, Medium, or Large”
- Size
- Methods:
- tip():
- Will print “This coffee is great, here’s a tip!”
- Will increase price by 1
- tip():
- Push feature branch and open a PR on GitHub
- Merge to main
Best Practice documentation steps:
- Add comments to code to explain purpose and logic. This clarifies intent / functionality of code to other developers
- Add screenshot of completed work included in Markdown in README.
- Update README text to reflect the functionality of the application following https://makeareadme.com.
- Delete any stale branches on GitHub
- Remove unnecessary/commented out code
- If needed, update git ignore to remove sensitive data
Before you submit your solution, you need to save your progress with git.
- Add your changes to the staging area by executing git add .
- Create a commit by executing git commit -m "Your commit message"
- Push your commits to GitHub by executing git push origin main or git push origin master , depending on the name of your branch (use git branch to check on which branch you are).
- Use the rubric in Canvas as a guide for how this lab is graded.
- Your submission will be automatically scored in CodeGrade, using the most recent commit. Remember to make sure you have pushed your commit to GitHub before submitting your assignment.
- You can review your submission in CodeGrade and see your final score in your Canvas gradebook.
- When you are ready to submit, click the Load Lab: Object Oriented Programming (OOP)- Part 1- Bookstore button in Canvas to launch CodeGrade.
- Click on + Create Submission. Connect your repository for this lab.
- For additional information on submitting assignments in CodeGrade: Getting Started in Canvas