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

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

  • Write code in static void main method class, which creates a boolean array called flags, size...

    Write code in static void main method class, which creates a boolean array called flags, size 10, and using a for loop sets each element to alternating values (true at index zero, false at index one Write code in a static void main method class, which creates a float array called sales, size 5, uses an initializer list to instantiate its elements with positive values having two decimal places (example 7.25), and using a for loop reads those values of...

  • Use of search structures! how can i make this program in python? Learning Objectives: You should...

    Use of search structures! how can i make this program in python? Learning Objectives: You should consider and program an example of using search structures where you will evaluate search trees against hash tables. Given the three text files under containing the following: - A list of students (classes Student in the distributed code) - A list of marks obtained by the students (classes Exam results in the distributed code) - A list of topics (classes Subject in the distributed...

  • Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user...

    Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user if they want to add a customer to the queue, serve the next customer in the queue, or exit. When a customer is served or added to the queue, the program should print out the name of that customer and the remaining customers in the queue. The store has two queues: one is for normal customers, another is for VIP customers. Normal customers can...

  • Write a program that does the following in Python Code: Stores the following three lists: last_name...

    Write a program that does the following in Python Code: Stores the following three lists: last_name = ["Smith", "Jones", "Williams", "Bailey", "Rogers", "Pyle", "Rossington"] first_name =["Lisa", "Bill", "Jay", "Sally", "Walter","Jake","Gary"] phone_number =["240-233-1921", "301-394-2745", "571-321-8934", "703-238-3432", "703-947-9987", "301-945-3593", "240-671-3221"] Has a function named combine_lists() that takes in last_names, first_names and phone_numbers as lists and returns a dictionary called phone_book that uses last_name as the key and a list consisting of first_name and phone_number. Has a main function that iterates through the...

  • Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this...

    Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this is in Zybooks Existing Code # Type code for classes here class ItemToPurchase: def __init__(self, item_name="none", item_price=0, item_quantity=0): self.item_name = item_name self.item_price = item_price self.item_quantity = item_quantity # def __mul__(self): # print_item_cost = (self.item_quantity * self.item_price) # return '{} {} @ ${} = ${}' .format(self_item_name, self.item_quantity, self.item_price, print_item_cost) def print_item_cost(self): self.print_cost = (self.item_quantity * self.item_price) print(('{} {} @ ${} = ${}') .format(self.item_name, self.item_quantity, self.item_price,...

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
ADVERTISEMENT