Thursday, 15 April 2010

python - Have no clue what has gone wrong here. I am sure this is the correct syntax, and I have checked for typos -



python - Have no clue what has gone wrong here. I am sure this is the correct syntax, and I have checked for typos -

# lists. months = [6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4] weekdays = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"] # functions algorithm. def yearcode(y): """generate year-code using algorithm""" y = y % 100 y = y + (y / 4) % 7 homecoming round(y) def monthcode(m): """get month number month-list""" homecoming months[monthin - 1] def daycode(d): """simplify day number efficiency""" homecoming d % 7 # inputs. dayayin = int(input("what day in month?")) monthin = int(input("what month? e.g.- jan 1")) yearin = int(input("what year?")) # define variables functions. yearout = yearcode(yearin) monthout = monthcode(monthin) dayout = daycode(dayin) # final add-up , output. result = (dayout + monthout + yearout) % 7 print(weekdays[result])

the error is: "parseerror: bad input on line 17" purpose of programme give day of week date. can see not happy how have given purpose of function benefit. sense missing here.

here improved , working version (thanks 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 algorithm. def yearcode(y): """year code generator algorithm""" y = y % 100 y = y + (y / 4) % 7 homecoming int(round(y)) def monthcode(m): """retrieve month number month list""" homecoming months[m - 1] def daycode(d): """simplify day input efficiency""" homecoming d % 7 # inputs. dayin = int(input("what day in month?")) monthin = int(input("what month? e.g.- jan 1")) yearin = int(input("what year?")) # define variables functions. yearout = yearcode(yearin) monthout = monthcode(monthin) dayout = daycode(dayin) # final add-up , output. result = int((dayout + monthout + yearout) % 7) print(weekdays[result])

you getting error because of issues mixing spaces tabs. seek run script

python -t yourscript.py

and see if tells anything.

perhaps, easier utilize builtin function in calendar module.

>>> import calendar >>> calendar.weekday(2013,2,18) 0 >>> calendar.day_name[calendar.weekday(2013,2,18)] 'monday'

as side note, running code, don't parseerror -- nameerror because dayin isn't defined. maybe didn't mean name dayayin?

python

No comments:

Post a Comment