Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING PYTHON 3. I ALWAYS RATE ANSWERS Program 8 Python\'s date time Module Use t

ID: 3829271 • Letter: U

Question

USING PYTHON 3. I ALWAYS RATE ANSWERS

Program 8 Python's date time Module Use these documents to study information about the module: Lecture on our class website: Python's date time Module Python's documentation for the date time module Create a create Menu function. It accepts 1 parameter (a list of options) and returns a string that contains a numbered list of options separated by newlines. Create a function get Valid Entry that has 2 integer parameters - begin, end. It should continue to ask the user to enter a number until their entry contains only digits and falls in the desired range. Example: if begin is 1 and end is 12, the user must enter a number from 1-12 inclusive. If being is 1 and end is 31, the user must enter a number from 1-31 inclusive. The function should return an integer. Create a function clades that takes 2 parameters of type date and returns an integer - the number of days between those dates. Note that the function should NOT print anything! Create another function calculative that takes 3 parameters-due Date, cur Date (both are objects of type date) and daily Fee (a float). It should return the amount to be assessed as the late fee. Cur Date can be any date-do NOT assume it is today's date! Daily Fee should be a float that indicates the amount per day to be charged if cur Date - due Date yields a negative number or 0, the function should return 0 as the amount. NOTE - make sure that the function does NOT return a negative value! Use the calk Days function within this function to help with the calculation! if the current Date is 1-15-2016 and the due Date was 1-1-2016 and the daily Late Fee is $10, the function should return 140 because 14 days have passed. if the current Date is 1-1-2016 and the due Date is 1-15-2016 and the daily Late Fee is $10, the function should return 0 (since the difference is -14) the main program should call the create Menu function ONLY ONCE to obtain a menu String. Then, it should continuously print the menu String and ask the user for their choice until the user chooses the Quit option. Use the get Valid Entry function to ensure the user enters an appropriate choice. Calculate the Days Between 2 Dates Calculate Late Fee Day of birth Quit If the user chooses option 1: ask the user to enter a month, day, and year for the first date, using 3 separate input statements. Then ask them to enter a month, day, and year for the second date. You can assume they will enter integers here - no error checking is needed. Call the calk Days function print the # of days AND the # of years that have passed If the user chooses option 2; ask the user to enter the information for 2 dates (use 6 input statements). Ask the user to enter the daily Late Fee. Call the calk Late Fee function and print the total amount due for the late payment. If the user chooses option 3: Ask the user to enter their birth date - use 3 separate input statements, please. Print the day name for the day they were born. Example: If the user entered 9 for the month, 1 for the day, and 2000 for the year, the output should be Friday +5 BONUS: explore Python's calendar module. Use it to ensure that the month, day, and year are valid entries. For example, if the month is 3 (March), the day must be a number 1-31, and if the month is February, the day must be either in the range 1-28 if it's not a leap year and in the range 1-29 if it is a leap year. There are methods in the calendar module to help with date validation.

Explanation / Answer

import datetime
import calendar

def calcDays(date1,date2):
   date3 = date1-date2
   return date3.days
def calcLateFee(date1,date2,fee):
   date3 = date2 - date1
   return date3.days *fee


while(True):
   print "1 Calculate Days Between twe dates"
   print "2 Calculate Late fee"
   print "3 Day of Birth"
   print "4 Quit"
   choice = int(raw_input("Enter Choice(1/2/3/4):"))
   if(choice == 1):
       print " Enter any date : "
       day = int(raw_input("Enter day:"))
       month = int(raw_input("Enter month:"))
       year = int(raw_input("Enter year:"))
       date1 = datetime.date(year, month, day)
       print " Enter another date : "
       day = int(raw_input("Enter day:"))
       month = int(raw_input("Enter month:"))
       year = int(raw_input("Enter year:"))
       date2 = datetime.date(year, month, day)
       print "Days :",calcDays(date1,date2)
   if(choice == 2):
       print " Enter due date: "
       day = int(raw_input("Enter day:"))
       month = int(raw_input("Enter month:"))
       year = int(raw_input("Enter year:"))
       date1 = datetime.datetime(year, month, day)
      
       print " Enter Current date: "
       day = int(raw_input("Enter day:"))
       month = int(raw_input("Enter month:"))
       year = int(raw_input("Enter year:"))
       fee = int(raw_input("Enter daily latefee:"))
       date2 = datetime.datetime(year, month, day)
       print "Total late fee :",calcLateFee(date1,date2,fee)
   if(choice == 3):
       print " Enter birth date: "
       day = int(raw_input("Enter day:"))
       month = int(raw_input("Enter month:"))
       year = int(raw_input("Enter year:"))
       date1 = datetime.datetime(year, month, day)
       print "Your day of birth is: ",calendar.day_name[date1.weekday()]
   if(choice==4):
       break;