Question

How do you do this? class Event: """A new calendar event.""" def __init__(self, start_time: int, end_time:...

How do you do this?

class Event:
"""A new calendar event."""

def __init__(self, start_time: int, end_time: int, event_name: str) -> None:
"""Initialize a new event that starts at start_time, ends at end_time,
and is named name.

Precondition: 0 <= start_time < end_time <= 23

>>> e = Event(12, 13, 'Lunch')
>>> e.start_time
12
>>> e.end_time
13
>>> e.name
'Lunch'
"""
  
self.start_time = start_time
self.end_time = end_time
self.name = event_name

def __str__(self) -> str:
"""Return a string representation of this event.

>>> e = Event(6, 7, 'Run')
>>> str(e)
'Run: from 6 to 7'
"""
  
return '{0}: from {1} to {2}'.format(self.name, self.start_time,
self.end_time)

class Day:
"""A calendar day and its events."""

def __init__(self, day: int, month: str, year: int) -> None:
"""Initialize a day on the calendar with day, month and year,
and no events.

>>> d = Day(5, 'April', 2014)
>>> d.day
5
>>> d.month
'April'
>>> d.year
2014
>>> d.events
[]
"""

# To do: Complete this method body.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

class Event:

    """A new calendar event."""

    def __init__(self, start_time: int, end_time: int, event_name: str) -> None:

        """Initialize a new event that starts at start_time, ends at end_time,

        and is named name.

        Precondition: 0 <= start_time < end_time <= 23

        >>> e = Event(12, 13, 'Lunch')

        >>> e.start_time

        12

        >>> e.end_time

        13

        >>> e.name

        'Lunch'

        """

        self.start_time = start_time

        self.end_time = end_time

        self.name = event_name

    def __str__(self) -> str:

        """Return a string representation of this event.

        >>> e = Event(6, 7, 'Run')

        >>> str(e)

        'Run: from 6 to 7'

        """

        return '{0}: from {1} to {2}'.format(self.name, self.start_time, self.end_time)

class Day:

    """A calendar day and its events."""

    def __init__(self, day: int, month: str, year: int) -> None:

        """Initialize a day on the calendar with day, month and year,

        and no events.

        >>> d = Day(5, 'April', 2014)

        >>> d.day

        5

        >>> d.month

        'April'

        >>> d.year

        2014

        >>> d.events

        []

       """

        self.day = day

        self.month = month

        self.year = year

        self.events = []

       

       

    def ScheduleEvent(self, e: "Event") -> None:

        """Schedule new_event on this day, even if it overlaps with

        an existing event. Later we will improve this method.

        >>> d = Day(5, 'April', 2014)

        >>> e = Event(6, 7, 'Run')

        >>> d.schedule_event(e)

        >>> d.events[0] == e

        True

        """

        self.events.append(e)

    def __str__(self) -> str:

        """Return a string representation of this day.

        >>> d = Day(4, 'April', 2014)

        >>> d.schedule_event(Event(12, 13, 'Lunch'))

        >>> d.schedule_event(Event(6, 7, 'Run'))

        >>> print(d)

        4 April 2014:

        - Lunch: from 12 to 13

        - Run: from 6 to 7

        """

        outputStr = "{:d} {:s} {:d}".format(self.day, self.month, self.year)

        for e in self.events:

          outputStr += "\n- {:s}".format(str(e))

        return outputStr

Output:

Add a comment
Know the answer?
Add Answer to:
How do you do this? class Event: """A new calendar event.""" def __init__(self, start_time: int, end_time:...
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
  • PYTHON -------------------------------------------------------- class LinkedList:    def __init__(self):        self.__head = None        self.__tail = None   

    PYTHON -------------------------------------------------------- class LinkedList:    def __init__(self):        self.__head = None        self.__tail = None        self.__size = 0    # Return the head element in the list    def getFirst(self):        if self.__size == 0:            return None        else:            return self.__head.element        # Return the last element in the list    def getLast(self):        if self.__size == 0:            return None        else:            return self.__tail.element    # Add an element to the beginning of the list    def addFirst(self, e):        newNode = Node(e) # Create a new node        newNode.next = self.__head # link...

  • ill thumb up do your best python3 import random class CardDeck: class Card: def __init__(self, value):...

    ill thumb up do your best python3 import random class CardDeck: class Card: def __init__(self, value): self.value = value self.next = None def __repr__(self): return "{}".format(self.value) def __init__(self): self.top = None def shuffle(self): card_list = 4 * [x for x in range(2, 12)] + 12 * [10] random.shuffle(card_list) self.top = None for card in card_list: new_card = self.Card(card) new_card.next = self.top self.top = new_card def __repr__(self): curr = self.top out = "" card_list = [] while curr is not None:...

  • in python and according to this #Creating class for stack class My_Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def Push(self, d): self.items.append(d) def Po...

    in python and according to this #Creating class for stack class My_Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def Push(self, d): self.items.append(d) def Pop(self): return self.items.pop() def Display(self): for i in reversed(self.items): print(i,end="") print() s = My_Stack() #taking input from user str = input('Enter your string for palindrome checking: ') n= len(str) #Pushing half of the string into stack for i in range(int(n/2)): s.Push(str[i]) print("S",end="") s.Display() s.Display() #for the next half checking the upcoming string...

  • class Leibniz:    def __init__(self):        self.total=0               def calculate_pi(self,n):       ...

    class Leibniz:    def __init__(self):        self.total=0               def calculate_pi(self,n):        try:            self.total, sign = 0, 1            for i in range(n):                term = 1 / (2 * i + 1)                self.total += term * sign                sign *= -1                self.total *= 4            return self.total        except Exception as e:   ...

  • In python class Customer: def __init__(self, customer_id, last_name, first_name, phone_number, address): self._customer_id = int(customer_id) self._last_name =...

    In python class Customer: def __init__(self, customer_id, last_name, first_name, phone_number, address): self._customer_id = int(customer_id) self._last_name = str(last_name) self._first_name = str(first_name) self._phone_number = str(phone_number) self._address = str(address) def display (self): return str(self._customer_id) + ", " + self._first_name + self._last_name + "\n" + self._phone_number + "\n" + self._address customer_one = Customer("694", "Abby", "Boat", "515-555-4289", "123 Bobby Rd", ) print(customer_one.display()) customer_two = Customer ("456AB", "Scott", "James", "515-875-3099", "23 Sesame Street Brooklyn, NY 11213") print(customer_two.display()) Use Customer class remove the address attribute.Place the code...

  • COMPLETE THE _CONSTRUCT() AND CONSTRUCTTREE() FUNCTIONS class expressionTree:    class treeNode: def __init__(self, value, lchild, rchild):...

    COMPLETE THE _CONSTRUCT() AND CONSTRUCTTREE() FUNCTIONS class expressionTree:    class treeNode: def __init__(self, value, lchild, rchild): self.value, self.lchild, self.rchild = value, lchild, rchild def __init__(self): self.treeRoot = None    #utility functions for constructTree def mask(self, s): nestLevel = 0 masked = list(s) for i in range(len(s)): if s[i]==")": nestLevel -=1 elif s[i]=="(": nestLevel += 1 if nestLevel>0 and not (s[i]=="(" and nestLevel==1): masked[i]=" " return "".join(masked) def isNumber(self, expr): mys=s.strip() if len(mys)==0 or not isinstance(mys, str): print("type mismatch error: isNumber")...

  • Can you complete the following code, please? Thank you. class BinaryNode: def __init__(self, valu...

    Can you complete the following code, please? Thank you. class BinaryNode: def __init__(self, value): self.__value = value self.__left = None self.__right = None self.__parent = None self.__height = 1    def getValue(self): return self.__value    def setHeight(self, height): self.__height = height    def getHeight(self): return self.__height    def setParent(self, node): self.__parent = node    def getParent(self): return self.__parent    def setLeftChild(self, child): self.__left = child child.setParent(self)    def setRightChild(self, child): self.__right = child child.setParent(self)    def createLeftChild(self, value): self.__left = BinaryNode(value)    def createRightChild(self, value): self.__right = BinaryNode(value)    def...

  • Use your Food class, utilities code, and sample data from Lab 1 to complete the following...

    Use your Food class, utilities code, and sample data from Lab 1 to complete the following Tasks. def average_calories(foods):     """     -------------------------------------------------------     Determines the average calories in a list of foods.     foods is unchanged.     Use: avg = average_calories(foods)     -------------------------------------------------------     Parameters:         foods - a list of Food objects (list of Food)     Returns:         avg - average calories in all Food objects of foods (int)     -------------------------------------------------------     """ your code here is the...

  • its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task an...

    its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task and Appointment which inherit from the Event class The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which designate the time of the event It should also have an integer member called id which should be a...

  • Question 3. [16 MARKS] Part (a) [4 MARKS Complete the Car class below. class Car: A...

    Question 3. [16 MARKS] Part (a) [4 MARKS Complete the Car class below. class Car: A Car class. we Attributes plate: this car's license plate number odometer: how many km this car has been driven in total plate: str odometer: int # TO DO: COMPLETE THE INITALIZER BELOW def __init__(self, plate: str) -> None: "Initialize a new Car with the given <plate>, and Okm on the odometer. >>> ci - Car ("AAA 111") >>> c1.plate "AAA 111" >>> ci.odometer #...

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