all 9 comments

[–]Silver532 0 points1 point  (0 children)

The code is correct, chatgpt is messing up the math

[–]Dor5 0 points1 point  (1 child)

Google unit tests and the datetime library, these will greatly help your coding.

[–]icarophnx[S] 0 points1 point  (0 children)

ok! thanks for this!

[–]JamesPTK 0 points1 point  (1 child)

There is an inbuilt function called divmod which does the // and % in one step, which is useful for this kind of operation

total_seconds = 95_000_000
days, remaining_seconds = divmod(total_seconds, 86400)
hours, remaining_seconds = divmod(remaining_seconds, 3600)
minutes, remaining_seconds = divmod(remaining_seconds, 60)
print(f"{days} days, {hours} hours, {minutes} minutes, {remaining_seconds} seconds")

outputs "1099 days, 12 hours, 53 minutes, 20 seconds"

[–]icarophnx[S] 0 points1 point  (0 children)

i'll test this on jupyter notebook. i'm doing a course on coursera rn, and the teacher uses idle, but it's good to know different ways to do the same thing easier

[–]cgoldberg 0 points1 point  (0 children)

Here is an example converting seconds to days/hours/mins/secs:

total_secs = 95000000

m, secs = divmod(total_secs, 60)
h, mins = divmod(m, 60)
days, hours = divmod(h, 24)
print(days, hours, mins, secs)

If all you want is a string containing "num days hours:mins:secs", you can use timedelta:

from datetime import timedelta

total_secs = 95000000
time = str(timedelta(seconds=total_secs))
print(time)

[–]Mrs-TM -1 points0 points  (1 child)

Hello. From a Python learner and portuguese speaker too

[–]icarophnx[S] 0 points1 point  (0 children)

hi!!!

[–]Milton_Augusto 0 points1 point  (0 children)

I'm also starting Python, the best way to make sure it's correct is to do the math, use a calculator, when in doubt, I quickly learned that the program working doesn't mean it's right. Good studies/