# Lists.
months = [6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
# Functions for algorithm.
def yearcode(y):
"""generate year-code using algorithm"""
y = y % 100
y = y + (y / 4) % 7
return round(y)
def monthcode(m):
"""get month number from month-list"""
return months[monthin - 1]
def daycode(d):
"""simplify day number for efficiency"""
return d % 7
# Inputs.
dayayin = int(input("What Day in the Month?"))
monthin = int(input("What Month? E.g.- January is 1"))
yearin = int(input("What Year?"))
# Define variables for functions.
yearout = yearcode(yearin)
monthout = monthcode(monthin)
dayout = daycode(dayin)
# Final Add-Up and Output.
result = (dayout + monthout + yearout) % 7
print(weekdays[result])
The Error is: "ParseError: bad input on line 17" The purpose of this program is to give the day of the week for any date. As you can see it is not happy with how I have given the purpose of the function for my benefit. I really feel like I am missing something here.
Here is the Improved and Working Version (Thanks for the help!)
# Lists.
months = [6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
# Fruitful Functions for Algorithm.
def yearcode(y):
"""Year Code Generator Algorithm"""
y = y % 100
y = y + (y / 4) % 7
return int(round(y))
def monthcode(m):
"""Retrieve Month Number from Month List"""
return months[m - 1]
def daycode(d):
"""Simplify Day Input for Efficiency"""
return d % 7
# Inputs.
dayin = int(input("What Day in the Month?"))
monthin = int(input("What Month? E.g.- January is 1"))
yearin = int(input("What Year?"))
# Define Variables for Functions.
yearout = yearcode(yearin)
monthout = monthcode(monthin)
dayout = daycode(dayin)
# Final Add-Up and Output.
result = int((dayout + monthout + yearout) % 7)
print(weekdays[result])