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 {...
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...
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...
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()
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...
I am having problems with an assignment for my class, I am struggling with part a...
I am having problems with an assignment for my class, I am struggling with part a of the following question. I included parts b-d as these additional questions may influence the answer to part a To generate leads for new business, Gustin Investment Services offers free financial planning seminars at major hotels in Southwest Florida. Gustin conducts seminars for groups of 25 individuals. Each seminar costs Gustin $3500, and the average first-year commission for each new account opened is $5000....
Hello, I feel like I am super close but I can not figure out why my...
Hello, I feel like I am super close but I can not figure out why my C++ code it not displaying the proper medium. Thank you! Here is an example of the output: Input : a[] = {1, 3, 4, 2, 6, 5, 8, 7} Output : Mean = 4.5 Median = 4.5 Code so far:   #include <iostream> using namespace std; int main() { int a[100]; int n,i,sum=0; float mean, medium; //read array size // read array cout<<"Enter array size:...
Python recursive design question: Background: The class vote creates vote objects. A vote is either a...
Python recursive design question: Background: The class vote creates vote objects. A vote is either a blue vote, a red vote, or a purple. This information is stored in the "value" attribute. The function Poll returns a list of random votes. In the code below, some_poll is a list of 32 random votes. some_poll = Poll(32) # ----------------------------------------------------- import random # ----------------------------------------------------- # # Return a list of n random votes # # ----------------------------------------------------- def Poll(n=16): # # A random...
Currently stuck on this part of a project. I am struggling with creating the String for...
Currently stuck on this part of a project. I am struggling with creating the String for creating the dice values in the boxes for the "showDice" string. I have already completed the first part which was creating the class for the Die. This is Javascript. For this part, we will create the class that allows you to roll and score the dice used in a game of Yahtzee. This will be the longest part of the project, so I suggest...