Python Forum
Calculating the number of day of the week
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculating the number of day of the week
#1
1. It is possible to name the days 0 through 6 where day 0 is Sunday and day 6 is Saturday. You want go on a summer holiday and you want to make reservation for it. You decided to go at next Thursday (day number 4) for 12 nights, you would return home on a Tuesday (day 2).

Day index 0 1 2 3 4 5 6
Day name Sunday Monday Tuesday Wednesday Thursday Friday Saturday


Write a python script which asks for the starting day number, and how many nights you want to go to holiday residence, and it will tell you the number of day of the week you will return on.
Reply
#2
the following will convert a datetime date to day of week:
it uses today(), but you can replace with another date
>>> from datetime import datetime
>>> datetime.today()
datetime.datetime(2020, 3, 27, 13, 15, 56, 364721)
>>> datetime.today().weekday()
4
Reply
#3
This is a math question. The day of the week is effectively a base 7 number because it resets to 0 every 7 days. We can use a modulus to calculate the remainder of any number divided by 7 to discern the progression to 7. For example, if we start on Sunday (0) and stay for 3 days, we can divided 3 by 7 and determine that the remainder is 3. Or we stay for 213 days; divide by 7... 30 and remainder 3.

To demonstrate with the example provided. You leave on Thursday (4) and stay for 12 days. If we add 4 and 12, we get 16. Divide by 7... 2 and remainder 2.

Since this is the homework forum, I won't do more. But you should have enough keywords here to devise a solution. Read up on the Python language documentation or your class materials.
Reply
#4
see: https://docs.python.org/3/library/dateti...te.weekday
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  hardest week yet: some guidence please raymond2688 25 10,650 Aug-22-2019, 05:23 PM
Last Post: ichabod801
  week 1 python help - string formatting ? raymond2688 20 7,732 Jul-09-2019, 08:10 PM
Last Post: snippsat
  Trying to get the week number from a string of numbers fad3r 2 3,189 Apr-15-2018, 06:52 PM
Last Post: ljmetzger

Forum Jump:

User Panel Messages

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