Question: using python 3: here i have a program that i need to fix: HERE MY PROGRAM: WHAT NEED TO BE FIXED HERE IS WHEN YOU
using python 3: here i have a program that i need to fix:
HERE MY PROGRAM: WHAT NEED TO BE FIXED HERE IS WHEN YOU RUN THE PROGRAM INSTEAD OF ASKING FOR THE YEAR, MONTH AND DAYS AT THE SAME TIME IT SHOULD ASK FOR THE YEAR CHECK IF IT IS IN THE CORRECT FORMAT, THEN FOR THE MONTH CHECK IF IT IS IN THE RIGHT FORMAT AND THEN THE SAME THING FOR THE DAY
from datetime import date def calcDiff(x,y): """ description: Create a function calcDiff that takes 2 parameters of type date and returns the difference of the dates precondition: parameters should be digits """ diff = abs(x - y) daysdiff = diff.days yearsdiff = 0 if daysdiff >= 365: yearsdiff = int(daysdiff / 365) daysdiff = daysdiff - ( yearsdiff * 365) print ("The given date differs from today's date by %d day(s) and %d year(s)" %(daysdiff,yearsdiff)) def getValidEntry(yr,month,day): """ description: create a function to make sure yr, month and day are valid entry precondition: parameters should be digits """ if (yr.isdigit() and month.isdigit() and day.isdigit()): return True else: return False def calcLateFee(dueDate,curDate,dailyfee): """ description: Create a function calcLateFee that takes 2 parameters of type dueDate, curDate (both are objects of type date) and dailyFee (a float). It should return the amount to be assessed as the late fee. precondition: curDate can be any date do NOT assume it is todays date! and dailyfee must be a float """ if dueDate >= curDate: return 0 else: return abs(((dueDate-curDate).days)*dailyfee) #main def main(): loop=True print("#Part 1 Execution of the Program") while(loop==True): userinput=input("Enter Year Month and Day in (Year-Month-Day) format:") if userinput=="END" or userinput=="end": loop=False break yr,month,day=userinput.split('-') if(getValidEntry(yr,month,day)==True): userdate=date(int(yr),int(month),int(day)) calcDiff(date.today(),userdate) print("#Part 2 Execution of the Program") dueDate=input("Enter Due date(In Year-Month-Day format):") yr,month,day=map(int,dueDate.split('-')) dueDate=date(yr,month,day) curDate=input("Enter Cur date(In Year-Month-Day format):") yr,month,day=map(int,curDate.split('-')) curDate=date(yr,month,day) dailyfee=float(input("Enter daily fee:")) print ("Latefee:%d " %calcLateFee(dueDate,curDate,dailyfee))
if __name__ == '__main__': main()
kkkkkkkk
Program 8- Using Python's DateTime Module Part 1: Create a function calcDiff that takes 2 parameters of type date and returns the difference of the dates. Note that the function should NOT print anything! Create a loop that Asks the user to enter a year, month, and day. Call the calcDiff function with today's date and the date entered by the user. Print the # of days AND the # of years that have passed. The loop should end when the usertypes END for the year. Reminders: Perform error-checking to ensure that the user enters only digits for each of the inputs (year, month, day) create a function getValidEntry that does the error checking. If the entry is not all digits, continue to ask the user for an entry until only digits are entered. Make sure your function does NOT return a negative number! Part 2: Create a function calcLateFee that takes 2 parameters of type dueDate, curDate (both are objects of type date) and dailyFee (a float). It should return the amount to be assessed as the late fee. curDate can be any date - do NOT assume it is today's date! dailyFee should be a float that indicates the amount per day to be charged if curDate - dueDate yields a negative number or 0, the function should return 0 as the amount. Scoring Guide: Part 1 (10 pts) - calcDiff takes 2 parameters, returns difference of the dates (4 pts). checks to make sure a negative # isn't returned -2 if no check prints # of days (2 pts) prints # of years (2 pts) Loops continuously until user types END (2 pts) Missing error checking on entries for yr, month, day -2 Part 2 (10 pts) calcLateFee takes 2 date objects as params and daily fee (float). Returns total late fee or 0 if no late feeStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
