Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

New to coding and I have to implement a function using a script that has already been written. The function I am implementing has specifications

New to coding and I have to implement a function using a script that has already been written. The function I am implementing has specifications of what it should be doing but I am really confused of what should be done? I have been trying to figure out what the function takes in and I have tried adding my inputs together but I get an error message that they cannot be added. I don't understand how to even begin this problem.

Blow is my code and the code that was already written to use in implementing the function add_time1:

My code

import clock from clock import Time

def add_time1(time1, time2): """ Returns the sum of time1 and time2 as a new Time object DO NOT ALTER time1 or time2, even though they are mutable Examples: The sum of 12hr 13min and 13hr 12min is 25hr 25min The sum of 1hr 59min and 3hr 2min is 5hr 1min Parameter time1: the starting time Precondition: time1 is a Time object Parameter time2: the time to add Precondition: time2 is a Time object """ print(time1) print(time2) time = Time(time1, time2) print(time)

code that was written already to use with (clock)

class Time(object): """ An instance represents a unit of time. Attributes: hours: Time in hours [int, must be nonnegative] minutes: Time in minutes [int in the rage 0..59] """ # Properties @property def hours(self): """ The number of hours in this time. **Invariant**: Value must be a positive int. """ return self._hours @hours.setter def hours(self, value): assert (type(value) == int), "value %s is not an int" % repr(value) assert (value >= 0), "value %s is not nonnegative" % repr(value) self._hours = value @property def minutes(self): """ The number of minutes in this time. **Invariant**: Value must be an int between 0 and 59, inclusive. """ return self._minutes @minutes.setter def minutes(self, value): assert (type(value) == int), "value %s is not an int" % repr(value) assert (value >= 0 and value <= 59), "value %s is outside of range [0,59]" % repr(value) self._minutes = value # Initializer def __init__(self,hours,minutes): """ **Constructor**: creates a new Time object with the given hours, minutes. Parameter hours: The number of hours Precondition: hours is a nonnegative int. Parameter minutes: The number of minutees Precondition: minutes is an int between 0 and 59, inclusive. """ self.hours = hours self.minutes = minutes def __eq__(self, other): """ Returns True if self and other are equivalent Time objects. Parameter other: The value to compare """ return (type(other) == Time and self.hours == other.hours and self.minutes == other.minutes) def __ne__(self, other): """ Returns True if self and other are not equivalent Time objects. Parameter other: The value to compare """ return not (self == other) def __str__(self): """ Returns a readable string representation of this time. """ min = str(self.minutes) if self.minutes < 10: min = '0'+min return str(self.hours)+":"+min def __repr__(self): """ Returns an unambiguous String representation of this time. """ return "%s(%s)" % (self.__class__,self.__str__())

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions