With two arms, a 12-hour clock runs from 00:00 to 11:59. One minute after 11:59, it goes back to 00:00. You will write a class Clock that implements the behaviors of such a clock via the following methods: definit_(self, initial_time: str) sets up the clock to the specified initial_time, which is guaranteed to be given in the format hh:mm (e.g., 11:24, 1:05, 08:07). Importantly, we guarantee that the given initial_time will be between 00:00 and 11:59. def forward(self, minutes: int) advances the time of the clock by minutes minutes. Keep in mind that our clock cannot display any number outside its range. Therefore, adjust the result accordingly. For example, adding 30 minutes to 11:40 will result in 00:10. The minutes parameter can be so large that the clock wraps around several times (e.g., 3800 minutes).

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

clock = Clock('02:05')
assert (clock.get_hour()==2)
assert (clock.get_minute()==5)
clock.forward(3726)
assert (clock.get_hour()==4)
assert (clock.get_minute()==11)
clock.reset()
assert (clock.get_hour()==0)
assert (clock.get_minute()==0)
clock.forward(3219)
assert (clock.get_hour()==5)
assert (clock.get_minute()==39)
clock.rewind(3551)
assert (clock.get_hour()==6)
assert (clock.get_minute()==28)
clock.rewind(900)
assert (clock.get_hour()==3)
assert (clock.get_minute()==28)
clock.rewind(656)
assert (clock.get_hour()==4)
assert (clock.get_minute()==32)
clock.rewind(2157)
assert (clock.get_hour()==4)
assert (clock.get_minute()==35)
clock.forward(1675)
assert (clock.get_hour()==8)
assert (clock.get_minute()==30)
clock.forward(2534)
assert (clock.get_hour()==2)
assert (clock.get_minute()==44)
clock.rewind(1670)
assert (clock.get_hour()==10)
assert (clock.get_minute()==54)
clock = Clock('11:35')
assert (clock.get_hour()==11)
assert (clock.get_minute()==35)
clock.reset()
assert (clock.get_hour()==0)
assert (clock.get_minute()==0)
clock.forward(2842)
assert (clock.get_hour()==11)
assert (clock.get_minute()==22)
clock.forward(3356)
assert (clock.get_hour()==7)
assert (clock.get_minute()==18)
clock.reset()
assert (clock.get_hour()==0)
assert (clock.get_minute()==0)
clock.forward(3777)
assert (clock.get_hour()==2)
assert (clock.get_minute()==57)
clock.rewind(3072)
assert (clock.get_hour()==11)
assert (clock.get_minute()==45)
clock.forward(1016)
assert (clock.get_hour()==4)
assert (clock.get_minute()==41)
clock.forward(4937)
assert (clock.get_hour()==2)
assert (clock.get_minute()==58)
clock.forward(4637)
assert (clock.get_hour()==8)
assert (clock.get_minute()==15)
clock.forward(1368)
assert (clock.get_hour()==7)
assert (clock.get_minute()==3)

Clock
With two arms, a 12-hour clock runs from 00:00 to 11:59. One minute after 11:59, it goes back to 00:00.
You will write a class Clock that implements the behaviors of such a clock via the following methods:
● def _init__(self, initial_time: str) sets up the clock to the specified initial_time, which is
guaranteed to be given in the format hh:mm (e.g., 11:24, 1:05, 08:07). Importantly, we guarantee
that the given initial_time will be between 00:00 and 11:59.
●
●
def forward(self, minutes: int) advances the time of the clock by minutes minutes. Keep in
mind that our clock cannot display any number outside its range. Therefore, adjust the result
accordingly. For example, adding 30 minutes to 11:40 will result in 00:10. The minutes parameter
can be so large that the clock wraps around several times (e.g., 3800 minutes).
def rewind (self, minutes: int) turns the time of the clock back by minutes minutes. Be careful
about the clock wrapping around. For example, subtracting 30 minutes from 12:15 will result in
11:45. The minutes parameter can be so large that the clock wraps around several times (e.g., 3800
minutes).
TEST CASES
def get_hour (self) -> int returns the hour of the clock. For example, if the current clock is 09:44,
this method returns the number 9.
def get_minute(self) -> int returns the minute of the clock. For example, if the current clock is
09:44, this method returns the number 44.
def reset (self) resets the clock to 0 hour and 0 minute.
An example usage of the clock class is below. Note that, in general, aside from
may be called in any order.
clock Clock ('01:01')
assert (clock.get_hour()==1)
assert (clock.get_minute()==1)
clock.rewind (2) # should be 0:59
assert (clock.get_hour()==0)
assert (clock.get_minute()==59)
clock. forward (63) # should be 2:02
assert (clock.get_hour () == 2)
assert (clock.get_minute()==2)
clock.reset() # should be 0:00
assert (clock.get_hour()==0)
assert (clock.get_minute()==0)
clock. forward (2423) # should be 4:23
assert (clock.get_hour() ==4)
assert (clock.get_minute()==23)
_init_
1
the methods
Your Submissions
Transcribed Image Text:Clock With two arms, a 12-hour clock runs from 00:00 to 11:59. One minute after 11:59, it goes back to 00:00. You will write a class Clock that implements the behaviors of such a clock via the following methods: ● def _init__(self, initial_time: str) sets up the clock to the specified initial_time, which is guaranteed to be given in the format hh:mm (e.g., 11:24, 1:05, 08:07). Importantly, we guarantee that the given initial_time will be between 00:00 and 11:59. ● ● def forward(self, minutes: int) advances the time of the clock by minutes minutes. Keep in mind that our clock cannot display any number outside its range. Therefore, adjust the result accordingly. For example, adding 30 minutes to 11:40 will result in 00:10. The minutes parameter can be so large that the clock wraps around several times (e.g., 3800 minutes). def rewind (self, minutes: int) turns the time of the clock back by minutes minutes. Be careful about the clock wrapping around. For example, subtracting 30 minutes from 12:15 will result in 11:45. The minutes parameter can be so large that the clock wraps around several times (e.g., 3800 minutes). TEST CASES def get_hour (self) -> int returns the hour of the clock. For example, if the current clock is 09:44, this method returns the number 9. def get_minute(self) -> int returns the minute of the clock. For example, if the current clock is 09:44, this method returns the number 44. def reset (self) resets the clock to 0 hour and 0 minute. An example usage of the clock class is below. Note that, in general, aside from may be called in any order. clock Clock ('01:01') assert (clock.get_hour()==1) assert (clock.get_minute()==1) clock.rewind (2) # should be 0:59 assert (clock.get_hour()==0) assert (clock.get_minute()==59) clock. forward (63) # should be 2:02 assert (clock.get_hour () == 2) assert (clock.get_minute()==2) clock.reset() # should be 0:00 assert (clock.get_hour()==0) assert (clock.get_minute()==0) clock. forward (2423) # should be 4:23 assert (clock.get_hour() ==4) assert (clock.get_minute()==23) _init_ 1 the methods Your Submissions
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education