Question: please modify the following python code to fix the logic errors: from datetime import datetime def calculate _ duration ( date _ str ) :
please modify the following python code to fix the logic errors: from datetime import datetime
def calculatedurationdatestr:
try:
inputdate datetime.strptimedatestrmdY
except ValueError:
return "Invalid date format. Please enter date in MMDDYYYY format."
currentdate datetime.now
duration currentdate inputdate
years duration.days
months durationdays
weeks durationdays
days durationdays
result fyears years, months months, weeks weeks, and days days ago."
return result
dateinput inputEnter a date MMDDYYYY:
printcalculatedurationdateinput
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
