Skip to content

Conversation

@lauramariel
Copy link
Contributor

ATTENTION: before clicking "Create Pull Request" please submit some meta data, thanks!

Difficulty level (1-10): 4
Estimated time spent (hours): <1
Completed (yes/no): yes
I stretched my coding skills (if yes what did you learn?): more practice with lists and datetime
Other feedback (what can we improve?): []

Copy link
Collaborator

@bbelderbos bbelderbos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!


def main():
pomodoro_count = 0
while True:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything that would break out of this loop?

from datetime import timedelta

def timer(timer_type):
if timer_type == "pomodoro":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only difference here are the number of minutes, so you could turn this into a dictionary: timer_times = {'pomodoro': 25, 'short_break': 5, 'long_break': 10}, then you don't have to repeat endtime = datetime.now() + timedelta(minutes=<int>) 3 times


while (datetime.now().replace(microsecond=0) != endtime.replace(microsecond=0)):
timeleft = endtime - datetime.now()
timeleft = str(timeleft).split(".")[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or:

>>> timeleft
datetime.timedelta(seconds=9, microseconds=687388)
>>> timeleft.seconds
9

while (datetime.now().replace(microsecond=0) != endtime.replace(microsecond=0)):
timeleft = endtime - datetime.now()
timeleft = str(timeleft).split(".")[0]
print(f"{timeleft}", end='\r')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is \r something you had to do for Windows?

@@ -0,0 +1,46 @@
import time
from datetime import datetime
from datetime import timedelta
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do in one import: from datetime import datetime, timedelta

@bbelderbos bbelderbos merged commit 549d9cc into pybites:community Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants