Question

Hello, I created a class in Python and am struggling to figure out how to complete...

Hello, I created a class in Python and am struggling to figure out how to complete the last part. How can you verify that a date is before in a pythonic way? I am struggling with the operands and what to check first. Thank you!

class Date(object):
"Represents a Calendar date"

def __init__(self, day=0, month=0, year=0):
"Initialize"
self.day = day
self.month = month
self.year = year


def __str__(self):
"Return a printable string representing the date: m/d/y"
return f'{self.month}/{self.day}/{self.year}'

def before(self, other):
"Is this date before that?"

Homework Answers

Answer #1
class Date(object):
    "Represents a Calendar date"

    def __init__(self, day=0, month=0, year=0):
        "Initialize"
        self.day = day
        self.month = month
        self.year = year

    def __str__(self):
        "Return a printable string representing the date: m/d/y"
        return f'{self.month}/{self.day}/{self.year}'

    def before(self, other):
        "Is this date before that?"
        if self.year < other.year:
            return True
        if self.year == other.year and self.month < other.month:
            return True
        if self.year == other.year and self.month == other.month and self.day < other.day:
            return True
        return False
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None:...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None: """This method adds new value to the tree, maintaining BST property. Duplicates must be allowed and placed in the right subtree.""" Example #1: tree = BST() print(tree) tree.add(10) tree.add(15) tree.add(5) print(tree) tree.add(15) tree.add(15) print(tree) tree.add(5) print(tree) Output: TREE in order { } TREE in order { 5, 10, 15 } TREE in order { 5, 10, 15, 15, 15 } TREE in order {...
"""linkedQueue.py implements LinkedQueue""" class Node(object): def __init__(self, e, nextNode): self.item, self.next = (e, nextNode) def __str__(self):...
"""linkedQueue.py implements LinkedQueue""" class Node(object): def __init__(self, e, nextNode): self.item, self.next = (e, nextNode) def __str__(self): return str(self.item)    class LinkedQueue(object): def __init__(self): #O(1) self._front, self._rear =(None, None) self._size = 0    def enqueue(self, e): # add e to the rear of the queue. newTail = Node(e, None) if self.isEmpty(): self._front = newTail else: self._rear.next = newTail self._rear = newTail self._size += 1 def front(self): # raise exception if it is empty, otherwise return front element if self.isEmpty(): raise Exception("call...
Python Problem 1 Create a function, biggest_ip_sum, outside of the ServerClass class, that: 1. Takes two...
Python Problem 1 Create a function, biggest_ip_sum, outside of the ServerClass class, that: 1. Takes two ServerClass objects 2. Sums the octets of the IP together (example 127.0.0.1 = 127+0+0+1 = 128) 3. Returns the larger number Example: server_one = ServerClass("127.0.0.1") server_two = ServerClass("192.168.0.1") result = biggest_ip_sum(server_one, server_two) print(result) In the example above, result will be 361. _________________________________ Problem 1 Here is the code to start with class ServerClass: """ Server class for representing and manipulating servers. """ def __init__(self,...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21,...
Python Blackjack Game Here are some special cases to consider. If the Dealer goes over 21, all players who are still standing win. But the players that are not standing have already lost. If the Dealer does not go over 21 but stands on say 19 points then all players having points greater than 19 win. All players having points less than 19 lose. All players having points equal to 19 tie. The program should stop asking to hit if...
I need some tests for this python class. some tests for some of the functions in...
I need some tests for this python class. some tests for some of the functions in this class like. def __init__ def __eq__ def __lt__ def __hash__ I am using Pycharm and useing Pytest to write some tests but have no idea how to write one --------------------------------------------------------------------------------------------------- class Movie: def __set_title_internal(self, title: str): if title.strip() == "" or type(title) is not str: self.__title = None else: self.__title = title.strip() def __set_release_year_internal(self, release_year: int): if release_year >= 1900 and type(release_year) is...
Hello I need a flowchart made for reference I am using flowgorithm Here is the python...
Hello I need a flowchart made for reference I am using flowgorithm Here is the python code that I need a flowchart for def get_user_input_validated(): """ Module Name: get_user_input_validated Parameters: None Description: Defence program validates input as rock, paper or scissors returns input in lowercase making input case insensitive """ choice=["rock","paper","scissors"] while True: user_choice = input("Please enter your choice (rock/paper/scissors):") if user_choice.lower() in choice: break else: print("Sorry - that selection is not valid.",end="") return user_choice.lower()
Python: Complete the function create_bfs_graph using python. Do not use any libraries def create_bfs_graph(): """ Initializes...
Python: Complete the function create_bfs_graph using python. Do not use any libraries def create_bfs_graph(): """ Initializes the undirected graph from the lecture    Uses the add_edge method    Returns Graph object of the lecture graph Example use: >>> ex_graph = create_bfs_graph() >>> [x in ex_graph.children_of('Jared') for x in ['John', 'Helena', 'Donald', 'Paul']] [False, False, True, True] >>> ex_graph = create_bfs_graph() >>> [x in ex_graph.children_of('Helena') for x in ['John', 'Helena', 'Donald', 'Paul']] [True, False, False, True] """ # DON'T CHANGE ANYTHING...
Hello, This is for my Finance class. I am trying to find the monthly return of...
Hello, This is for my Finance class. I am trying to find the monthly return of some stocks. I have the Opening Price and the Closing price for each month. I have calculated the monthly return using this formula: (Closing Price - Starting Price) / Starting Price Is this the accurate formula? Here is the data and my answers for the first few months. Are they correct? Opening Closing Return 56.30 60.71 .0783 60.95 55.98 -.0815 55.92 55.57 -.0063 55.65...
Hello, I am trying to use python to calculate the terminal velocity of an object falling...
Hello, I am trying to use python to calculate the terminal velocity of an object falling from a height of 3 meters. I have gotten stuck trying to actually calculate the terminal velocity. thanks for the help! Here I have posted the code I have so far. from visual import* myscene = display(range = 10, width = 600, heigth = 600, background = color.blue, title = 'lab 5' ) #display window s = vector(0,3,0) #vector for starting position m =...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance:...
Assignment Statement Use the skeleton file starter code (below) to create the following classes using inheritance: ⦁   A base class called Pet ⦁   A mix-in class called Jumper ⦁   A Dog class and a Cat class that each inherit from Pet and jumper ⦁   Two classes that inherit from Dog: BigDog and SmallDog ⦁   One classes that inherit from Cat: HouseCat The general skeleton of the Pet, Dog, and BigDog classes will be given to you (see below, "Skeleton", but...