I'm going to add more and more

Asked 2 years ago, Updated 2 years ago, 17 views

I have to solve this problem I wrote the code like this, but if the time interval goes over 60 minutes, if it goes well, there's an error when it's less than 60 minutes If there is no error when it is less than 60 minutes, there will be an error when it is over 60 minutes Help me

python

2022-09-20 17:23

1 Answers

Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> h, m = 12, 0
>>> gap, n = 180, 10
>>> 
>>> hm = h*60 + m
>>> 
>>> for hm_ in range(hm, hm+gap*(n+1), gap):
    h_, m_ = divmod(hm_, 60)
    h_ %= 24
    print(f"{h_:02d}:{m_:02d} Carrot Time!")


12:00 Carrot Time!
15:00 Carrot Time!
18:00 Carrot Time!
21:00 Carrot Time!
00:00 Carrot Time!
03:00 Carrot Time!
06:00 Carrot Time!
09:00 Carrot Time!
12:00 Carrot Time!
15:00 Carrot Time!
18:00 Carrot Time!
>>> hm_sleep = 22*60
>>> for hm_ in range(hm, hm+gap*(n+1), gap):
    if hm_ >= hm_sleep:
        print("Emergency!")
        break
    h_, m_ = divmod(hm_, 60)    
    print(f"{h_:02d}:{m_:02d} Carrot Time!")


12:00 Carrot Time!
15:00 Carrot Time!
18:00 Carrot Time!
21:00 Carrot Time!
Emergency!
>>> h, m = 9, 20
>>> gap, n = 72, 7
>>> hm = h*60 + m
>>> for hm_ in range(hm, hm+gap*(n+1), gap):
    if hm_ >= hm_sleep:
        print("Emergency!")
        break
    h_, m_ = divmod(hm_, 60)
    print(f"{h_:02d}:{m_:02d} Carrot Time!")


09:20 Carrot Time!
10:32 Carrot Time!
11:44 Carrot Time!
12:56 Carrot Time!
14:08 Carrot Time!
15:20 Carrot Time!
16:32 Carrot Time!
17:44 Carrot Time!
>>> hm = h*60 + m
>>> for hm_ in range(hm, hm+gap*n, gap):
    if hm_ >= hm_sleep:
        print("Emergency!")
        break
    h_, m_ = divmod(hm_, 60)
    print(f"{h_:02d}:{m_:02d} Carrot Time!")


09:20 Carrot Time!
10:32 Carrot Time!
11:44 Carrot Time!
12:56 Carrot Time!
14:08 Carrot Time!
15:20 Carrot Time!
16:32 Carrot Time!


2022-09-20 17:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.