Output weekday in python?
Hello everyone!
I'm currently working on a task where I receive a number k between 1 and 365 from a user input. Based on this, I then need to output the day of the week (the number) to the console, where 0 = Sunday, 1 = Monday, 2 = Tuesday, 6 = Saturday, etc.
I'm kind of confused here ๐ก
Thanks for your input! ๐
The task is actually just about modulo.
This is the solution:
or somewhat simplified:
-1 to change โ1 to 365โ to โ0 to 364โ, since the range of weekdays also starts with zero.
Modulo 7 to determine the day of the week.
However, the zeroth day would be Sunday. Therefore, add 4 and modulo 7 to shift the weekday four days (Sun -> Thurs, Mon -> Fri, โฆ), since it starts on Thursday.
Thank you very much! Now I understand ๐
Freut mich, gerne ๐
You need more than just a number, you also need to know the year, but there is a general formula for this: https://de.wikipedia.org/wiki/Wochentagsberechnung#:~:text=Um%20den%20Wochentag%20mit%20Hilfe,ganzzahligen%20Division%20%C3%BCbrig%20bleibt%20(z.
Oh stimmt, es startet beim Januar 1, welcher die Nummer 4 ist (Donnerstag)
Leap year yes/no?
Ah nevermind, number from 1-365