Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question: Convert convertToSeconds (from Section 13.5) to a method in the Time c

ID: 3619810 • Letter: Q

Question

Question: Convert convertToSeconds (from Section 13.5) to a
method in the Time class.
--
The reading for this question is posted below.
---
Another example:

Let’s convert increment (from Section 13.3) to a method. To save space, we will
leave out previously defined methods, but you should keep them in your version:
class Time:
   #previous method definitions here...
   def increment(self, seconds):
      self.seconds = seconds + self.seconds
      while self.seconds >= 60:
         self.seconds = self.seconds - 60
         self.minutes = self.minutes + 1
   while self.minutes >= 60:
         self.minutes = self.minutes - 60
         self.hours = self.hours + 1
The transformation is purely mechanical—we move the method definition into the
class definition and change the name of the first parameter.
Now we can invoke increment as a method. currentTime.increment(500)
Again, the object on which the method is invoked gets assigned to the first pa-
rameter, self. The second parameter, seconds gets the value 500. Question: Convert convertToSeconds (from Section 13.5) to a
method in the Time class.
--
The reading for this question is posted below.
---
Another example:

Let’s convert increment (from Section 13.3) to a method. To save space, we will
leave out previously defined methods, but you should keep them in your version: class Time:
   #previous method definitions here...
   def increment(self, seconds):
      self.seconds = seconds + self.seconds       while self.seconds >= 60:
         self.seconds = self.seconds - 60
         self.minutes = self.minutes + 1
   while self.minutes >= 60:
         self.minutes = self.minutes - 60
         self.hours = self.hours + 1 The transformation is purely mechanical—we move the method definition into the
class definition and change the name of the first parameter. Now we can invoke increment as a method. currentTime.increment(500)
Again, the object on which the method is invoked gets assigned to the first pa-
rameter, self. The second parameter, seconds gets the value 500.

Explanation / Answer

Dear,

ConvertToSeconds method in time class with time object as parameter

class Time:
def ConvertToSeconds(time1):
minutes = time1.hours * 60 + time1.minutes
seconds = minutes * 60 + time1.seconds
return seconds
To invoke this function >>> time1 = Time() //object name time1
with all attributes values initialized then >>> seconds=ConvertToSeconds(time1) Hope this will help you..
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote