Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a PYTHON program that computes the cost of a long-distance call. The cost of the call is determined according to the following rate schedule:

Write a PYTHON program that computes the cost of a long-distance call.

The cost of the call is determined according to the following rate schedule:

a. Any call started between 8:00 A.M. and 6:00 P.M., Monday through Friday, is billed at a rate of $0.40 per minute.

b. Any call starting before 8:00 A.M. or after 6:00 P.M., Monday through Friday, is charged at a rate of $0.25 per minute.

c. Any call started on a Saturday or Sunday is charged at a rate of $0.15 per minute.

The input will consist of the day of the week, the time the call started, and the length of the call in minutes. The output will be the cost of the call. The time is to be input in 24-hour notation, so the time 1:30 P.M. is input as (must be the following format, the user types in the colon): 13:30

The day of the week will be read as one of the following pairs of character values, which are stored in two variables of type string (ex. a, b = "Mo"): Mo Tu We Th Fr Sa Su

Be sure to allow the user to use either uppercase or lowercase letters or a combination of the two. The number of minutes will be input as a value of integer.

Format your output to two decimal places.

Define the following lists and fill the lists using the two functions (createList() and fillList()):

Calling the functions (copy the following statements into your program):

hoursList = createList(24)

fillList (24, hoursList)

minutesList = createList(60)

fillList (60, minutesList)

hoursList = [0, 1, 2, .........., 22, 23] minutesList = [0, 1, 2, .........., 58, 59] 

Define the following lists and fill the lists manually (copy the following code and paste into your program):

daysList = ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su'] responseList = ['y', 'n']

Define the following functions:

createList(listSize): accepts a listSize as a argument, create a 1-D list called timeList with the listSize (initial values: zeros), and returns the timeList list.

fillList(listSize, timeList): accepts a listSize and the list returned by createList() as arguments, and fill the passed list. This is a void function.

collectUserInputTime(): accepts no arguments, collects call starting time in 24-hour notation, and returns startHour and startMinute as string data type.

validateUserInputTime(startHour, startMinute): accepts the startHour and startMinute returned by collectUserInputTime() as arguments, validates the user's time input by comparing to the lists called hoursList and minutesList, and returns True, startHour (integer), startMinute (integer) if the input is valid, or False if the input is invalid.

collectUserInputDay(): accepts no arguments, collects a day (two characters) save as firstDayCharacter and secondDayCharacter, and returns firstDayCharacter and secondDayCharacter as string data type. Allow uppercase and lowercase input (ex. MO, Mo, mo, and mO).

validateUserInputDay(firstDayCharacter, firstDayCharacter): accepts the firstDayCharacter and secondDayCharacter returned by collectUserInputDay(), validates the user's day input by comparing the input to the daysList list, and returns True if the input is valid, or False if the input is invalid.

collectUserInputCallLength(): accepts no arguments, collects call length in in 24-hour notation, and returns callLengthHour and callLengthMinute as string data type.

validateUserInputCallLength(callLengthHour, callLengthHour): accepts the callLengthHour and callLengthMinute as arguments returned by collectUserInputCallLength(), validates the user's call length input (callLengthHour and callLengthMinute should be greater than or equal to zero), and returns True, callLengthHour (integer), callLengthMinute (integer) if the input is valid, or False if the input is invalid.

calculateTotalCost(startHour, startMinute, firstDayCharacter, secondDayCharacter, callLengthHour, callLengthMinute): Accepts arguments (startHour, startMinute, firstDayCharacter, secondDayCharacter, callLengthHour, callLengthMinute), calculate the total cost of a call, and returns the total cost (float).

collectUserInputYesNo(): accepts no arguments, collects 'y' or 'n' save as YesOrNo, and returns YesOrNo as string data type. Allow uppercase and lowercase input (ex. Y, y, N, n).

validateUserInputYesNo(YesOrNo): accepts the YesOrNo an argument returned by collectUserInputYesNo(), validates the user's input by comparing the input to the responseList list, and returns True if the input is valid, or False if the input is invalid.

clearPreviousOutput(YesOrNo ): accepts the YesOrNo an argument. If the response is 'y' or 'Y', then clear the previous output, otherwise doesn't clear the previous output.

***Be sure to allow the user to type lowercase as well as uppercase characters.

*************************************************************************************

OUTPUT:

- The bold text is the user's input.

**************************************************************************************

Enter the time the call starts in 24-hour rotation: -13:10 Invalid time input. Please try again. Enter the time the call starts in 24-hour rotation:

**************************************************************************************

Enter the time the call starts in 24-hour rotation: a:77 Invalid time input. Please try again. Enter the time the call starts in 24-hour rotation:

**************************************************************************************

Enter the time the call starts in 24-hour rotation: 13:10 Enter the first two letters of the day of the week: ss Invalid day input. Please try again. Enter the first two letters of the day of the week:

**************************************************************************************

Enter the time the call starts in 24-hour rotation: 13:10 Enter the first two letters of the day of the week: 1s Invalid day input. Please try again. Enter the first two letters of the day of the week:

**************************************************************************************

Enter the time the call starts in 24-hour rotation: 13:10 Enter the first two letters of the day of the week: Mo Enter the length of the call in (hours:minutes): -10:10 Invalid call length input. Please try again. Enter the length of the call in (hours:minutes):

**************************************************************************************

Enter the time the call starts in 24-hour rotation: 13:10 Enter the first two letters of the day of the week: Mo Enter the length of the call in (hours:minutes): a1:10 Invalid call length input. Please try again. Enter the length of the call in (hours:minutes):

**************************************************************************************

Enter the time the call starts in 24-hour rotation: 13:10 Enter the first two letters of the day of the week: Mo Enter the length of the call in (hours:minutes): 0:10 Cost of the call: $4.00 Do you want to repeat the program (y/n)? >>y

**************************************************************************************

Enter the time the call starts in 24-hour rotation: 20:10 Enter the first two letters of the day of the week: Fr Enter the length of the call in (hours:minutes): 0:10 Cost of the call: $2.50 Do you want to repeat the program (y/n)? >>yes Invalid response. Please try again. Do you want to repeat the program (y/n)? >>y 

**************************************************************************************

Enter the time the call starts in 24-hour rotation: 10:10 Enter the first two letters of the day of the week: Su Enter the length of the call in (hours:minutes): 1:40 Cost of the call: $150.00 Do you want to repeat the program (y/n)? >>n

**************************************************************************************

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 2 Lnai 8725

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448505, 978-3662448502

More Books

Students also viewed these Databases questions