2017-09-27 4 views
0

유일한 문제는 프로그램을 실행할 때 연, 월, 일을 입력 한 후 요일이 인쇄되지 않는다는 것입니다. 내가 누락되었거나 적어도 힌트를 얻을 수 있습니까?Python 입문. Zeller의 알고리즘 관련 문제

여기 내 프로그램이 있습니다 (아래). 곰곰이 생각해 볼 때, 저는 파이썬과 코딩 분야에 처음으로 익숙해졌습니다.

감사합니다.

데프 주() :

#Prompt User to enter year within range 1900 and 2100 
year = eval(input("Enter year: ")) 

while(year < 1900 or year > 2100): 
    year = eval(input("Enter year: ")) 
    print(year) 

#Prompt User to enter month as a number 
month = eval(input("Enter month: ")) 

while(month < 1 or month > 12): 
    month = eval(input("Enter month: ")) 
    print(month) 

#Prompt User to enter day as a number 
day = eval(input("Enter day: ")) 

#Restrict the entry of numbered days based on the month and account for leap year in February 
while((month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12) \ 
     and (day > 31 or day < 1)): 
    day = eval(input("Enter day: ")) 

if(month == 2 and year % 4 == 0): 
    while(day < 1 or day > 29): 
     day = eval(input("Enter day: ")) 
    print(day) 
elif(month == 2): 
    while(day < 1 or day > 28): 
     day = eval(input("Enter day: ")) 
     print(day) 

if(month == 4,6,9,11): 
    while(day < 1 or day > 30): 
     day = eval(input("Enter day: ")) 
     print(day) 

#Change in year if month is January or February 
if((month == 1) or (month == 2)): 
    year = year - 1 

#Switch months so that March becomes the first month of the year and January/ February become the 11th and 12th months respectively 
#Convert variables to algorithm variables (so a = month and b = day) 
    if(month < 3): 
    a = month + 10 
    else: 
    a = month - 2 

    b = day 

    c = year % 100 

    d = year // 100 

    #Compute r with algorithm 
    w = (13 * a - 1) // 5 

    x = c // 4 

    y = d // 4 

    z = w + x + y + b + c - 2 * d 

    r = z % 7 

    r = (r + 7) % 7 

    #Set conditions so r[0,6] prints a day of the week [Sunday == 0 , Saturday == 6] 
    if(r == 0): 
     print("The day is Sunday") 
    elif(r == 1): 
     print("The day is Monday") 
    elif(r == 2): 
     print("The day is Tuesday") 
    elif(r == 3): 
     print("The day is Wednesday") 
    elif(r == 4): 
     print("The day is Thursday") 
    elif(r == 5): 
     print("The day is Friday") 
    elif(r == 6): 
     print("The day is Saturday") 

주()

+0

D : D : D : 고함을 지르는 것에 대해 미안; 'eval'이 안전하지 않기 때문에'int (input())'을 대신 사용하십시오;) – HyperNeutrino

답변

0

들여 쓰기 수준

월 미만 3 인 경우 당신은 라인 47에서 당신의 들여 쓰기 수준을 변경하지 않은

, 그것을 10을 더하고 아무 것도하지 않습니다. 그렇지 않으면 계속 진행됩니다.

실제로 41과 같이 들여 쓰기 수준을 변경하지 않았습니다. 1 또는 2이면 1에서 1을 뺀 다음 계속 진행합니다. 그렇지 않으면 모든 것을 건너 뜁니다. 그래서 당신이 이것을 원한다 :

# etc 

if 1 <= month <= 2: 
    year -= 1 

if month < 3: 
    a = month + 10 
else: 
    a = month - 2 

b = day 

# etc