0

Can someone explain this code to me?

def dayofweek(d, m, y): t = [ 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 ] y -= m < 3 return (( y + int(y / 4) - int(y / 100) + int(y / 400) + t[m-1] +d) %7) day = dayofweek (8, 12, 2018) print (day) What do the indented lines mean?

9th Dec 2018, 1:45 PM
Holly Smith
Holly Smith - avatar
6 Answers
+ 3
No. It's not a function. 't' is just an arbitrary variable and 't= [........]' means you're just assigning a list to the variable 't'
9th Dec 2018, 2:20 PM
Шащи Ранжан
Шащи Ранжан - avatar
+ 2
It'd be better to help if you can write this code in the playground and share it's link over here. It's python and it works on indentation the same way other languages work on '{...}'. In Python, indentation is the space left in front of every line of code. Every line should have same indentation, means same number of spaces should be left in front of every line with respect to it's above line or else there'll be a syntax error.
9th Dec 2018, 2:15 PM
Шащи Ранжан
Шащи Ранжан - avatar
+ 2
y -= m < 3 is the same as: if m < 3: y = y - 1 For the leap years the function adds an extra '1' to the result, but for Jan and Feb it is must not be done. So there is a correction for first and second months.
9th Dec 2018, 3:08 PM
portpass
+ 1
If the year isn't bissextile it contains 365 days. Also we have 7 days in a week. 365 = 52 * 7 + 1. So the remainder of the division of 365 by 7 is 1 (365 % 7 == 1). This means that for a given date every non-leap year shifts the day of the week by one. For instance: 2017-12-09 - Saturday 2018-12-09 - Sunday 2019-12-09 - Monday So for non-leap years we can calculate the number of the day of the week as: (y + C) % 7 Where y is number of the year and C is number of the days from 1 of the January to the given date. As every month of the non-leap year contains certain number of the days, the day of the week can be calculated as: (y + T + d) % 7, where T depends of the number of the month. t = [ 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 ] is the list of this values int(y / 4) - int(y / 100) + int(y / 400) is the correction for the leap year. https://en.m.wikipedia.org/wiki/Leap_year
9th Dec 2018, 3:56 PM
portpass
0
https://code.sololearn.com/chy8aqpV0veY/?ref=app what does ‘t=‘ function mean? ‘table?’
9th Dec 2018, 2:18 PM
Holly Smith
Holly Smith - avatar
0
thank you. what do the other two lines mean?
9th Dec 2018, 2:49 PM
Holly Smith
Holly Smith - avatar