Question
Task 01 (10 points) This assignment will be incredibly open ended, this is by design. I want you to have some freedom to create something
Task 01 (10 points)
This assignment will be incredibly open ended, this is by design. I want you to have some freedom to create something that you are interested in rather than just following along with what I tell you to do. Feel free to go as far as youd like with your script, dont just stop with the bare minimum. And remember to have fun! Scripts will be graded on how much fun you have.
Create a class of your choosing. It can be an animal class or a bankaccount class. Choose something that you are passionate about and familiar with and create it. For the purposes of illustration, I will be using a dog class as an example. While I would prefer you to create your own unique class, you may use a dog class so long as you do not copy my code and you are super passionate about dogs. Your class should have the following:
- Three protected class variables to store key information about the class
- An __init__ constructor that populates the aforementioned class variables
Example structure |
class Dog: size = smol rate = 10 name = Schmoopy __init__(size, rate, name): size = size rate = 10 name = name |
Task 02 (10 points)
Now its time to add some interactivity to your previous script. Take the class you created in the add the following:
- One method that will accept an input, update one of the class variables, and return the new value
- One method that will accept an input, perform some kind of error checking, update one of the class variables, and return the new value
Example structure |
set_size(newsize): size = newsize return size
increment_cute(number): if rate < 10: rate += number return rate else return false |
Task 03 (20 points)
Now were going to add even more interactivity to your class. Building on what you have so far, you will now add the following:
- overload the str() and len() methods to return useful information for your class
- overload the equivalence operator (==) such that its use with your class will compare one of the variables and return true if they are the same and false otherwise
Example structure |
__str__(): return name
__len__(): return size __==__(otherdog): if rate == otherdog.rate return True else return False |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started