Skip to content

Conversation

Danielef12
Copy link

No description provided.


timer_data["format"] = select

def countdown():
Copy link

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():
Copy link

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']
Copy link

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():
Copy link

@effedib effedib Jun 23, 2025

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":
Copy link

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()
Copy link

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
Copy link

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

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.

2 participants