Question

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...

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
self.day = day
self.year = year
  
def __str__(self):
template = "{first} {last} was born on the {month}/{day}/{year}"

  
return template.format(
first=self.first,
last=self.last,
month=self.month,
day = self.day,
year = self.year)
  
class Famous_Person_Day(Famous_Person):
  
def calculate_day(self):
#insert your code here
# The method creates a datetime class of the Famous_person birthdate
# and returns the weekday of the birthdate.
  
def find_day(self):
#insert your code here
# calls calculate_day to find weekday
# and uses if-statement to finds and returns the actual weekday
  
  
def main():
  
george_w = Famous_Person_Day(last="Washington",
first="George",
month = 2,
day = 22,
year = 1732
)
  
isaac_n = Famous_Person_Day(last="Newton",
first="Isaac",
month = 1,
day = 4,
year = 1643
)
albert_e = Famous_Person_Day(last="Einstein",
first="Albert",
month = 3,
day = 14,
year = 1879
)
  

print(george_w)
wday = george_w.find_day()
print (wday)
  
#Print a blank line
print()
  
print(isaac_n)
wday = isaac_n.find_day()
print (wday)
  
#Print a blank line
print()
  
print(albert_e)
wday = albert_e.find_day()
print (wday)
  

  
if __name__ == "__main__":
main()

////////////////////////////////////////////

Test your code and make sure it is error-free and works correctly.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.
Here is the completed code for this problem.  Let me know if you have any doubts or if you need anything to change.
Thank You !!
========================================================================================
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
        self.day = day
        self.year = year


    def __str__(self):
        template = "{first} {last} was born on the {month}/{day}/{year}"
        return template.format(first=self.first, last=self.last, month=self.month, day=self.day, year=self.year)


class Famous_Person_Day(Famous_Person):

    def calculate_day(self):
        dt = datetime(self.year, self.month, self.day)
        return dt.weekday()

    # insert your code here
    # The method creates a datetime class of the Famous_person birthdate
    # and returns the weekday of the birthdate.

    def find_day(self):
        weekday = self.calculate_day()
        if weekday == 0:
            return 'Monday'
        elif weekday == 1:
            return 'Tuesday'
        elif weekday == 2:
            return 'Wednesday'
        elif weekday == 3:
            return 'Thursday'
        elif weekday == 4:
            return 'Friday'
        elif weekday == 5:
            return 'Saturday'
        else:
            return 'Sunday'
    def __str__(self):
        return super().__str__()  +' '+self.find_day()


def main():


    george_w = Famous_Person_Day(last="Washington",
                                 first="George",
                                 month=2,
                                 day=22,
                                 year=1732
                                 )

    isaac_n = Famous_Person_Day(last="Newton",
                                first="Isaac",
                                month=1,
                                day=4,
                                year=1643
                                )
    albert_e = Famous_Person_Day(last="Einstein",
                                 first="Albert",
                                 month=3,
                                 day=14,
                                 year=1879
                                 )

    print(george_w)
    wday = george_w.find_day()
    print(wday)

    # Print a blank line
    print()

    print(isaac_n)
    wday = isaac_n.find_day()
    print(wday)

    # Print a blank line
    print()

    print(albert_e)
    wday = albert_e.find_day()
    print(wday)

if __name__ == "__main__":
    main()

==========================================================================================

Add a comment
Know the answer?
Add Answer 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...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born...

    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...

  • ### Question in python code, write the code on the following program: def minmaxgrades(grades, names): """...

    ### Question in python code, write the code on the following program: def minmaxgrades(grades, names): """ Computes the minimum and maximujm grades from grades and creates a list of two student names: first name is the student with minimum grade and second name is the student with the maximum grade. grades: list of non-negative integers names: list of strings Returns: list of two strings """ def main(): """ Test cases for minmaxgrades() function """ input1 = [80, 75, 90, 85,...

  • PYTHON The provided code in the ATM program is incomplete. Complete the run method of the...

    PYTHON The provided code in the ATM program is incomplete. Complete the run method of the ATM class. The program should display a message that the police will be called after a user has had three successive failures. The program should also shut down the bank when this happens. [comment]: <> (The ATM program allows a user an indefinite number of attempts to log in. Fix the program so that it displays a message that the police will be called...

  • 11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl...

    11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...

  • ***IN PYTHON 2.7****Augment the following code with a new class named 'Coin'. Coin should inherit from...

    ***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...

  • PYTHON 3.6 Overview In this assignment we implement a class called TripleString. It consists of a...

    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...

  • Python has the complex class for performing complex number arithmetic. For this assignment, you will design...

    Python has the complex class for performing complex number arithmetic. For this assignment, you will design and implement your own Complex class. Note that the complex class in Python is named in lowercase, while our custom Complex class is named with C in uppercase. A complex number is of the form a + bi, where a and b are real numbers and i is √-1. The numbers a and b are known as the real part and the imaginary part...

  • PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment...

    PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...

  • PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please...

    PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList:     def __init__(self):         self.__head = None         self.__tail = None         self.__size = 0     def insert(self, i, data):         if self.isEmpty():             self.__head = listNode(data)             self.__tail = self.__head         elif i <= 0:             self.__head = listNode(data, self.__head)         elif i >= self.__size:             self.__tail.setNext(listNode(data))             self.__tail = self.__tail.getNext()         else:             current = self.__getIthNode(i - 1)             current.setNext(listNode(data,...

  • Need help finishing this code # Description : The Pet class contains fields for name, pet...

    Need help finishing this code # Description : The Pet class contains fields for name, pet # type,and age. The age field is the age now # or age of pet when it passed away. (These # are all dogs I have had.) There is a static or # class variable called number_pets that # tracks how many instances have been created. # The constructor will fill all fields and add # one to the number_pets variable. # The special...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT