Hi so I have created but it needs updates to it and I'm not sure how to fix them, the updates include; First, remember t

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Hi so I have created but it needs updates to it and I'm not sure how to fix them, the updates include; First, remember t

Post by answerhappygod »

Hi so I have created but it needs updates to it and I'm not sure
how to fix them, the updates include;
First, remember that one of the requirements of
3.3P was that the clock output its time in the format "HH:MM:SS".
This means that the numbers must be zero-padded here as well.
Second, your clock shouldn't print out the time
by itself - it should only return it.
Finally, your incre_second, incre_minute and
incre_hour methods aren't private and allow external code to modify
the time via other means than the intended "tick" method.
The Python Program that goes as follows(please make sure to use
my code as a base and help fix accordingly):
from time import sleep
class Counter:
def __init__(self, name):
self.name = name
self.count = 0
def increment(self):
self.count += 1
def reset_Clock(self):
self.count = 0
@property
def time(self):
return self.count
class Clock:
def __init__(self):

self.seconds = Counter("seconds")

self.minutes = Counter("minutes")
self.hours
= Counter("hours")
def incre_second(self):
if(self.seconds.time <
59):

self.seconds.increment()
else:

self.inc_minute()

self.seconds.reset_Clock()
def incre_minute(self):
if(self.minutes.time <
59):

self.minutes.increment()
else:

self.inc_hour()

self.minutes.reset_Clock()
def incre_hour(self):
if(self.hours.time <
23):

self.hours.increment()
else:

self.hours.reset_Clock()
def tick(self):
self.incre_second()
def use_time(self):

print(f'{self.hours.time}:{self.minutes.time}:{self.seconds.time}')
clock = Clock()
while True:
clock.tick()
clock.use_time()
sleep(1)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply