On 3/4/19 1:15 PM, David Rock wrote:
On Mar 4, 2019, at 13:19, Alan Gauld via Tutor <tutor@python.org> wrote:

On 04/03/2019 18:54, john fabiani wrote:

I need to print out the weeks of the month - given any month and any year.
I'm not totally clear how you define a week.

EDIT: OK I see the comment at the end now.

For example this month would have:

3/1/2019 - 3/3/2019   # notice that this a short week
3/4/2019 - 3/10/2019
3/11/2019 - 3/17/2019
3/18/2019 - 3/24/2019
3/25/2019 - 3/31/2019  # also this can be a short week as in April 2019
last week would be 4/29/2019 - 4/30-2019
What I think he’s shooting for is something similar to cal output

$ cal
      March 2019
Su Mo Tu We Th Fr Sa
                 1  2
  3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31


So what I think you want is to

start with the first day and print each day up to Sunday.
Newline
print the current date up to sunday
newline
repeat until you run out of days in the month.


import calendar as cal
cal.monthcalendar(2019,3)
[[0, 0, 0, 0, 1, 2, 3], [4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16,
17], [18, 19, 20, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30, 31]]
That looks close to what you want?

That seems close, but off by a day?


—
David Rock
da...@graniteweb.com
I knew there was a simple why to get it done!  But where is it off my a day?

Johnf
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to