Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- The program should take three arguments. The first will be a day, the second will be month, and the third will be year. Then, your program should compute the day of the week that date will fall on.
- """
- import sys
- import calendar
- months = {
- 'january':1,
- 'february':2,
- 'march':3,
- 'april':4,
- 'may':5,
- 'june':6,
- 'july':7,
- 'august':8,
- 'september':9,
- 'october':10,
- 'november':11,
- 'december':12
- }
- weekday = {
- 0:'monday',
- 1:'tuesday',
- 2:'wednesday',
- 3:'thursday',
- 4:'friday',
- 5:'saturday',
- 6:'sunday',
- }
- def get_args():
- "Returns a dict of args"
- if len(sys.argv) <= 3:
- print "Not enough arguments!"
- print "I need:"
- print "\tThe day [1]"
- print "\tThe month [2]"
- print "\tThe year [3]"
- sys.exit(0)
- try:
- month = months[sys.argv[2].lower()]
- except:
- try:
- month = int(sys.argv[2])
- except:
- month = months[sys.argv[2]]
- return {'day': int(sys.argv[1]),'month':month,'year':int(sys.argv[3])}
- def main(year,month,day):
- int_day = calendar.weekday(year,month,day)
- print weekday[int_day]
- if __name__ == "__main__":
- date = get_args()
- year = date['year']
- month = date['month']
- day = date['day']
- main(year,month,day)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement