-
Notifications
You must be signed in to change notification settings - Fork 2
My solution for final project #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
My solution for final project #143
Conversation
|
||
timer_data["format"] = select | ||
|
||
def countdown(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why nested functions? Functions exist to avoid code repetitions declaring only 1 time the function and calling it multiple times. How you can call your function if it exists only inside another function? This is the opposite of the DRY principle, don't repeat yourself
import time | ||
import threading | ||
|
||
def currentTime(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to separate the business logic from the utility function used i.e. to print results... what happens if your code evolves and you have to put your output in a file or the input arrives from an API call instead of console?
|
||
def countdown(): | ||
while not stop.is_set(): | ||
current_time = timer_data['time'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are using variables as if they were global not being declared inside the function nor passed as a parameter, this exposes you to potential bugs. It's a best practice to make the function as isolated and self-consistent as possible
Added module division and "refinement" of functions according to latest instructions
import threading | ||
|
||
|
||
def set_timer(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this func contains a bug, if you enter a number <= 0
it starts an infinite loop (and this is the reason why we have to avoid infinite loops) without exit caused by absence of another input inside the loop.
This changed version would work correctly:
while (timer := int(input("Enter a time in seconds: "))) <= 0:
print("Value of timer must be greater than 0.")
return timer
|
||
while True: | ||
command = input("\n>>>").strip().lower() | ||
if command == "start": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to use match case
statement
from main import main | ||
|
||
if __name__ == '__main__': | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the entrypoint would be main.py
not index.py
, better to switch them
"""function to elaborate choice""" | ||
while choice in ["1", "2", "3", "4", "5"]: | ||
if choice == "1": | ||
from current_time import show_date_time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to use black and isort for code formatting
No description provided.