I need help in Python !!! Please

232 views
Skip to first unread message

王功荃

unread,
Oct 26, 2016, 4:22:06 AM10/26/16
to Python Challenge
I want to write a code about the Zeller's congruence!!  The code below is written to print out the day of the date. But it cany't have the right answe.
Please help!



y=int(input('Enter year:(e.g,2008):'))
m=int(input('Enter month: 1-12:'))
q=int(input('Enter the day of the month:1-31:'))

if m==1 or m==2:
    n=12
    m=m+n
    
j=y/100
k=y%100


h = int((((q + 26 * (m + 1) / 10 + k + (k/4) + (j/4) + 5 * j))% 7))
if h==0:
    print('Saturday')
elif h==1:
    print('Sunday')
elif h==2:
    print('Monday')
elif h==3:
    print('Thuesday')
elif h==4:
    print('Wednesday')
elif h==5:
    print('Thrusday')
elif h==6:
    print('Friday')

Arpit Singh

unread,
Oct 26, 2016, 4:26:26 AM10/26/16
to Python Challenge
What is the error you are getting in this ?

王功荃

unread,
Oct 26, 2016, 4:31:34 AM10/26/16
to Python Challenge
When I put 2013/1/25 the answer should be Friday but instead it keep showing Sunday.

Arpit Singh於 2016年10月26日星期三 UTC+8下午4時26分26秒寫道:

Arpit Singh

unread,
Oct 26, 2016, 2:13:30 PM10/26/16
to Python Challenge
Use this for the day:

For an ISO week date Day-of-Week d (1 = Monday to 7 = Sunday), use

d=((h+5)mod7)+1

Arpit Singh

unread,
Oct 26, 2016, 2:16:22 PM10/26/16
to Python Challenge
y=int(input('Enter year:(e.g,2008):'))
m=int(input('Enter month: 1-12:'))
q=int(input('Enter the day of the month:1-31:'))

if m==1 or m==2:
    n=12
    m=m+n
    
j=y/100
k=y%100


h = int((((q + (26 * (m + 1) / 10) + k + (k/4) + (j/4) -(2*j)))% 7))

d = ((h+5)% 7)+1
if d==0:
    print('Saturday')
elif d==1:
    print('Sunday')
elif d==2:
    print('Monday')
elif d==3:
    print('Thuesday')
elif d==4:
    print('Wednesday')
elif d==5:
    print('Thrusday')
elif d==6:
    print('Friday')


This works exactly as you want
Reply all
Reply to author
Forward
0 new messages