Python3 : question about object-oriented programming, Please write program in the template(critter.py),specific information is on the graphs
the missing words in the 4th line are 'To save an attribute, attach it to this self keyword'




# TEXT CODE FOR critter.py
# defining Critter class
class Critter:
# defining constructor method
def __init__(self, species, size, age):
# set attribute species to
parameter attribute
self.species = species
# set attribute size to
parameter size
self.size = size
# set attribute age to parameter
age
self.age = age
# defining can_eat() method
def can_eat(self, prey):
# if size of Critter is greater
then prey return true.
if self.size > prey.size:
return True
# Otherwise return False
else: return False
# defining survive_year() method
def survive_year(self):
# increase the size and age by
1
self.size = self.size + 1
self.age = self.age + 1
# return the current size
return self.size
# defining test() method to test the Critter class
def test():
# creating objects of Critter class
centipede = Critter("centipede", 3, 1)
millipede = Critter("millipede", 3, 1)
spider = Critter("Orb Weaver", 50, 1)
# check whether millipede can eat centipede or not
by calling can_eat() method of critter
print("millipede can " , end = "")
if millipede.can_eat(centipede):
print("eat centipede")
else: print("not eat centipede")
# check whether spider can eat millipede or not
print("spider can " , end = "")
if spider.can_eat(millipede):
print("eat millipede")
else: print("not eat millipede")
# print the age of spider
print("Age of spider is: ", spider.age)
# print the current age of spider by calling
survive_year() method
print("Current age of spider is: ",
spider.survive_year())
# TEXT CODE FOR run.py
# importing test function from critter
from critter import test
# call test() method
test()
SCREENSHOTS
critter.py


run.py

output (after running run.py):

Python3 : question about object-oriented programming, Please write program in the template(critter.py),specific information is on the graphs the missing words in the 4th line are 'To save an attri...
Write a python program using Object Oriented and do the following: 1. create class "cat" with the following properties: name, age (create constructor method: def __init__) 2. create class "adopter" with the following properties: name, phone 3. create class "transaction" with these properties: adopter, cat (above objects) cat1 = "puffy, 2" adopter1 = "Joe, 123" Test your program: Joe adopts puffy. Print: "Per Transaction 1 <joe> has adopted <puffy>" this can only be done with object oriented programming, no way...
***IN PYTHON 2.7****Augment the following code with a new class named 'Coin'. Coin should inherit from Die, with the following modifications; The constructor should not take any arguments; a coin always has two sides add a flip() method that uses the roll() method from the parent class. If roll returns 1; flip should return "HEADS". If roll returns a 2, flip should return "TAILS" Do not override the roll or rollMultiple methods from the parent class #!/usr/bin/python # your class...
This is my assignment in Python. Please help me thank you Design type 1: # Creating an object of the class "Burger" theOrder = Burger() # calling the main method theOrder.main() # And the class is like: class Burger: # You may need to have a constructor def __init__(self): self._orderDict = {} self._priceBeforeTax = 0 self._priceAfterTax = 0 # you may have the tax rate also as an instance variable. But as I mentioned, you can use your # own...
PYTHON 3.6 Overview In this assignment we implement a class called TripleString. It consists of a few instance attribute and a few instance methods to support those attributes. In the next assignment, the TripleString class will help us create a more involved application. Before we do that though, we have to thoroughly test our TripleString implementation. Specifications The class TripleString will contain symbolic constants, instance attributes, and instance methods. ▶ Class symbolic constants This class has 3 symbolic constants, which...
Objectives: Develop an object-oriented program Develop a test program that is separate from the class under development ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Define a class where one object of the class represents a playing card. If you are not familiar with a deck of playing cards, you will need to spend some time understanding the rank and suit that is on each playing card. You can look it up in wikipedia and see an image of the whole deck of 52 playing cards here:...
It's my python homework. Not Java. Design type 1: # Creating an object of the class "DeAnzaBurger" theOrder = DeAnzaBurger() # calling the main method theOrder.main() # And the class is like: class DeAnzaBurger: # You may need to have a constructor def __init__(self): self._orderDict = {} self._priceBeforeTax = 0 self._priceAfterTax = 0 # you may have the tax rate also as an instance variable. But as I mentioned, you can use your # own deign. .... # That...
Java - Object Oriented Programming
Declare a class named Customer that has two private fields? Write a set method to make sure that if age > 125 years or less than 0 then it is set to 0 (default value) What does it indicate when declaring a class's instance variables with private access modifier? What is the role of a constructor? The data part of by an object's instance variables is known as? Do all methods have to always return...
Write a C++ program for the instructions below. Please
read the instructions carefully and make sure they are followed
correctly.
and please put comment with code!
Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...
Below is the Graph file that
needs to be modified(using Python3) :
#!/usr/bin/python3
# Simple Vertex class
class Vertex:
""" Lightweight vertex structure for a graph.
Vertices can have the following labels:
UNEXPLORED
VISITED
Assuming the element of a vertex is string type
"""
__slots__ = '_element', '_label'
def __init__(self, element, label="UNEXPLORED"):
""" Constructor. """
self._element = element
self._label = label
def element(self):
""" Return element associated with this vertex. """
return self._element
def getLabel(self):
""" Get label assigned to...
Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...