Current code to fix: def usage(): TODO enter docstring pass # TODO: delete this line,
Question:
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
Systems analysis and design
ISBN: 978-0136089162
8th Edition
Authors: kenneth e. kendall, julie e. kendall