I’ll help you with some parts, but most of this code should be a learning experience for you.
import datetime
# prompt here for the date
# put it into a datetime.datetime object named "day"
# this is the part of the code you need to type
day_array = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
day_of_week = day_array[day.weekday()]
The datetime
module should be your go-to when working with dates. It gives you a comprehensive object with a list of methods relating to time and date, which is EXACTLY what you’re looking for. You initialize a datetime
object using datetime.datetime(YEAR,MONTH,DAY)
(where you fill in the year, month, and day). You can also set a time, but it’s not necessary in your use case.
The datetime object has a method called weekday
that returns a number (0
through 6
) that represents which day of the week that day represents. I built an array day_array
that maps each day to the index it represents (e.g., a Monday will return 0
, so day_array[0] == "Monday"
and etc).
At this point, it’s child’s play. The hard part is going to be to prompt the user for a day and convert that into a datetime object. That I’ll leave for you.
solved I don’t know what to do next [closed]