Question: Current code to fix: def usage(): TODO enter docstring pass # TODO: delete this line, replace with valid code. def valid_date(date: str) ->

Final Submission For the final submission you should integrate your functions into

Current code to fix:

def usage():
   "TODO enter docstring"
   pass # TODO: delete this line, replace with valid code.

def valid_date(date: str) -> bool:
   "TODO enter docstring"
   # return True or False
   pass # TODO: delete this line, replace with valid code.

def leap_year(year: int) -> bool:
   "takes a year in YYYY format, and returns True if it's a leap year, False otherwise."
   lyear = year % 4
   if lyear == 0:
      feb_max = 29 # this is a leap year
   else:
      feb_max = 28 # this is not a leap year

   lyear = year % 100
   if lyear == 0:
      feb_max = 28 # this is not a leap year

   lyear = year % 400
   if lyear == 0:
      feb_max = 29 # this is a leap year
     
   if feb_max == 29:
      return True
   else:
      return False

def after(date: str) -> str:
   "after takes a valid date string in YYYY format and returns"
   "a date string for the next day in YYYY-MM-DD format."
   if len(date) != 10:
       return '0000-00-00'

   else:
       str_year, str_month, str_day = date.split('-')
       year = int(str_year)
       month = int(str_month)
       day = int(str_day)

  feb_max = leap_year(year)

  tmp_day = day + 1

       mon_max = { 1:31, 2:29 if feb_max else 28, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31}
       
       if tmp_day > mon_max[month]:
           to_day = tmp_day % mon_max[month]
           tmp_month = month + 1
       else:
           to_day = tmp_day
           tmp_month = month + 0

       if tmp_month > 12:
           to_month = 1
           year = year + 1
       else:
           to_month = tmp_month + 0

       next_date = f"{year}-{to_month:02}-{to_day:02}"
       return next_date

def before(date: str) -> str:
   "TODO enter docstring."
    pass
       
def dbda(start_date: str, step: int) -> str:
   "given a start date and a number of days into the past/future, give date"
   end_date = 0
   temp_date = start_date

   if int(num_days) >= 0:
       for day in range(num_days):
           temp_date = after(temp_date)
   else:
       num_day = num_days * -1
       for day in range(num_day):
           temp_date = before(temp_date)

   end_date = temp_date
 
   return end_date

if __name__ == "__main__":
   # process command line arguments
   # call dbda()
   # output the result
   pass

Final Submission For the final submission you should integrate your functions into a working script, add relevant comments and implement some error checking so that invalid dates or arguments will cause a usage message to be displayed. 1. In the main block, check the number of arguments. The first argument should be a valid date, and the second should be a divisor of a typical year (365 days). 2. A divisor of 2 would mean dividing a year by half. This gives us 182 days. (This is rounded down, use the round() function). 3. Print the number of days for the divisor. 4. Use one call to dbda () to return the date that's 182 days before the start date. 5. Use a second call to dbda () to return the date that's 182 days after the start date. At this point you have a working script. Implement error checking: 1. Complete the usage() function. This should print a helpful message to the user when they make a mistake, and exit. 2. Complete the valid_date() function. This should use error checking to make sure that any date entered by the user is valid. 3. Ensure that the divisor argument is not zero! This would cause a Divide by zero error.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!