Python Forum
what have you learned recently?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what have you learned recently?
#11
(Sep-01-2022, 07:47 AM)Gribouillis Wrote: A shorter way
days, hrs = divmod(hours, day)

Thank you: that's two things I've learned today Smile
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#12
(Sep-01-2022, 06:54 AM)rob101 Wrote: This could be extended to weeks for days, months for weeks, and so on.

how many weeks in a month?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#13
(Sep-01-2022, 07:40 PM)Skaperen Wrote: how many weeks in a month?
>>> days_per_year = 365.2422
>>> weeks_per_year = days_per_year / 7
>>> weeks_per_year
52.17745714285714
>>> weeks_per_month = weeks_per_year / 12
>>> weeks_per_month
4.348121428571429
rob101 likes this post
Reply
#14
(Sep-01-2022, 07:40 PM)Skaperen Wrote: how many weeks in a month?

I'd calculate that as 4.333 weeks in a month:~ 91 days = 3 month = 13 weeks.

4.333 * 3 is as close to 13 as makes no odds, but I've yet to work all of that in to my little script, so I'm unsure if it's going to work right now.

To add...

This is as far as I've got, as it's as far as I needed, for the time being:

hours = your_input

day  = 24
week = 7

days, hours = divmod(hours, day)
weeks, days = divmod(days, week)

if weeks:
    output = "Weeks: {}, Days: {}, Hours: {}".format(weeks, days, hours)
elif days:
    output = "Days: {}, Hours: {}".format(days, hours)
else:
    output = "Hours: {}".format(hours)

print(output)
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#15
i could add that the Gregorian calendar (not perfect) repeats every 400 years with exactly 20871 weeks (coincidence?), so for usage over the Gregorian calendar, that would be 20871/4800 or about 4.348125 weeks per month. i don't have the scientific figures for the moon and earth but 365.2422 is familiar, though i tend to use 365.2425 for calendar purposes.
rob101 likes this post
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  recently seen on another website Skaperen 1 2,309 Jul-20-2018, 09:34 PM
Last Post: nilamo
  Just learned that Unity is gone wavic 10 8,272 Apr-12-2017, 09:38 AM
Last Post: wavic
  first learned python metulburr 12 10,502 Jan-03-2017, 05:21 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020