Python Function for Year, Month, Date & Day

Hi All

I have written following Python Function which should return Day, when year, month & date is provided to function.
For Testing, I have limit it to 3 years & then call it using for loop. But it always return “Saturday”.
What’s wrong in function.

Code:
def dayOfYear(y,m,d):
if y in [2018,2019,2020]:
if m in [1,2,3]:
if d in [31,28,1]:
return(‘Saturday’)
else:
return(‘Thursday’)
else:
return(‘Sunday’)
else:
return(None)

for i in range(len(testYears)):
yr = testYears[i]
mo = testMonths[i]
dn = testDaysNo[i]
td = testDays[i]
print(yr, mo, dn, td, " -> “, end=”")
result = dayOfYear(yr,mo,dn)
if result == testDays[i]:
print(“OK”)
else:
print(“Failed”)

Hi Shahzad,

hard to tell - as your code lacks any indents… You can use the </> button to insert your code WITH indents…

By the way, may I propose having a look at:

datetime — Basic date and time types — Python 3.9.4 documentation

too?

Have Fun, Dominik