Question: Write a function printTime that takes a Time object as an argument and
ID: 3619801 • Letter: Q
Question
Question: Write a function printTime that takes a Time objectas an argument and prints it in the form hours:minutes:seconds.
--
The reading for this question is posted below.
---
Time:
As another example of a user-defined type, we’ll define a class called Time that
records the time of day. The class definition looks like this: class Time:
pass We can create a new Time object and assign attributes for hours, minutes, and
seconds: time = Time()
time.hours = 11
time.minutes = 59
time.seconds = 30 The state diagram for the Time object looks like this:
Explanation / Answer
Dear, Print function for class Time class Time:def printTime(time):
print str(time.hours) + ":" +
str(time.minutes) + ":" +
str(time.seconds) To invoke this function we need to create object for class time and then initialize its attributes with given values such as 10,59,30. >>> time1 = Time() //object name time1
>>> time1.hours = 10
>>> time1.minutes = 59
>>> time1.seconds = 30
>>> printTime(time1) //passing time object i.e time1 as parameter Hope this will help you... Hope this will help you...
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.