''' day_week_born.py ask to enter a birthday and show the day of the week the person was born some dates in history ... July 4, 1776 was on a Thursday December 7, 1941 was on a Sunday 3/14/1879 was on a Friday (Albert Einstein's birthday aka. pi-day) tested with Python32/33 by vegaseat 14feb2013 ''' import datetime as dt while True: # stay in the loop until correct date is entered try: # for Python2 replace input() with raw_input() birthday_str = input("Enter birthday (format mm/dd/yyyy): ") m, d, y = birthday_str.split('/') birthday = dt.date(int(y), int(m), int(d)) if int(y) > 1700: break except: print("Please enter correct date!") week_day = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] sf = "If you were born on %s, you were born on a %s" print(sf % (birthday_str, week_day[dt.date.weekday(birthday)]))
Are you able to help answer this sponsored question?
Questions asked by members who have earned a lot of community kudos are featured in order to give back and encourage quality replies.