Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started