Lightbulb Start Watching
This is the second mission in the lightbulb series. I will try to make each following task slightly more complex.
You have already learned how to count the amount of time a light bulb has been on, or how long a room has been lit. Now let's add one more parameter - the counting start time.
This means that the light continues to turn on and off as before. But now, as a result of the function, I want not only to know how long there was light in the room, but how long the room was lit, starting from a certain moment.
One more argument is added – start_watching, and if it’s not passed, we count as in the previous version of the program for the entire period.
Input: Two arguments and only the first one is required. The first one is a list of datetime objects and the second one is a datetime object.
Output: A number of seconds as an integer.
Example:
sum_light([ datetime(2015, 1, 12, 10, 0, 0), datetime(2015, 1, 12, 10, 0, 10), ], datetime(2015, 1, 12, 10, 0, 5)) == 5 sum_light([ datetime(2015, 1, 12, 10, 0, 0), datetime(2015, 1, 12, 10, 0, 10), ], datetime(2015, 1, 12, 10, 0, 0)) == 10 sum_light([ datetime(2015, 1, 12, 10, 0, 0), datetime(2015, 1, 12, 10, 10, 10), datetime(2015, 1, 12, 11, 0, 0), datetime(2015, 1, 12, 11, 10, 10), ], datetime(2015, 1, 12, 11, 0, 0)) == 610
Precondition:
- The array of pressing the button is always sorted in ascending order
- The array of pressing the button has no repeated elements
- The amount of elements is always even (the light will eventually be off)
- The minimum possible date is 1970-01-01
- The maximum possible date is 9999-12-31
CheckiO Extensions allow you to use local files to solve missions. More info in a blog post.
In order to install CheckiO client you'll need installed Python (version at least 3.8)
Install CheckiO Client first:
pip3 install checkio_client
Configure your tool
checkio --domain=py config --key=
Sync solutions into your local folder
checkio sync
(in beta testing) Launch local server so your browser can use it and sync solution between local file end extension on the fly. (doesn't work for safari)
checkio serv -d
Alternatevly, you can install Chrome extension or FF addon
checkio install-plugin
checkio install-plugin --ff
checkio install-plugin --chromium
Read more here about other functionality that the checkio client provides. Feel free to submit an issue in case of any difficulties.
Welcome to Pair Programming! Engage in real-time collaboration on coding projects by starting a session and sharing the provided unique URL with friends or colleagues. This feature is perfect for joint project development, debugging, or learning new skills together. Simply click 'Start Session' to begin your collaborative coding journey!
You are trying to join a pair programming session that has not started yet.
Please wait for the session creator to join.
It looks like the creator of the pair programming session closed the editor window.
It might happen accidentally, so that you can wait for reconnection.