Question: Write a program named babysitter.py that takes as inputs the hourly rate and the start and end times of a babysitters service, and computes the

Write a program named babysitter.py that takes as inputs the hourly rate and the start and end times of a babysitters service, and computes the total time worked and the total amount earned by the babysitter.

Step 1: The program should begin by getting the following inputs from the user:

the babysitters hourly rate in dollars

the start time as a string of the form hour XM, where hour is an integer from 1-12 and XMis either AM or PM. For example, two possible start times are 9 AM and 8 PM.

the end time, also as a string of the form hour XM.

Note that each of the times will be entered as a single input. Below is an example of what the initial interaction with the user should look like.

Enter the hourly rate in dollars: 6 Enter the start time: 11 AM Enter the end time: 6 PM 

Because the hourly rate is a number, you should use a combination of the int and inputfunctions to obtain that value from the user.

However, because the user will enter strings for the start and end times, you should use the input function by itself without the int function when obtaining those values. Use descriptive variable names for each of the inputs.

Step 2: The program should then extract the two components (hour and period (AM or PM)) of the start time and store them in variables named start_hour and start_period.

We encourage you to start by using the split method to split the string entered for the start time into a list of two strings. Your code should look like this:

components = variable.split() 

where you will need to replace variable with the variable that you used for the start time.

After the line above is executed, components should represent a list of two strings. You can then write code that (1) converts the first of these strings into an integer and assigns the resulting value to the appropriate variable, and (2) stores the second string in the appropriate variable. Your code should look like this:

start_hour = int(...) start_period = ... 

You will need to replace the two ellipses (...) with appropriate expressions. Dont forget that you can access the components of a list in the same way that you access the characters in a string.

Step 3: Next, extract the two components of the deadline and turn them into integers that you store in variables named end_hour and end_period. Use a procedure similar to the one outlined above for Step 2.

Step 4: Compute the number of hours that the babysitter worked, and store that number in an appropriately named variable.

We recommend that you begin by converting the values of both start_hour and end_hour to 24-hour time. In this time system, an hour is an integer between 0 and 23. 12 AM = 0, 1 AM = 1, 2 AM = 2, ..., 12 PM = 12, 1 PM = 13, 2 PM = 14, ..., 11 PM = 23.

To perform these conversions, you will need to write assignment statements that update the value of start_hour and end_hour as needed, and you will need to use some type of conditional execution (if-else, if-elif-else, etc.) to govern which updates are made. You may assume that midnight (12 AM) will not be entered.

You should only need a small number of cases for each variable, with each case corresponding to a range of hours. You should not need a separate if or elif case for each value of start_hour and end_hour that needs to be converted.

Step 5: After converting to 24-hour time, perform whatever additional computations are needed to determine the number of hours that the babysitter worked, and store that number in a variable with an appropriate name.

You may make the following simplifying assumptions:

The start time and end time are during the same day.

The end time is after the start time.

Midnight (12 AM) will not be entered.

If you have converted the start and end times to 24-hour time, these assumptions should make it possible to use a simple computation to determine the number of hours worked, without using any conditional execution.

Step 6: Compute the amount earned by the babysitter, and print both the number of hours worked and the amount earned. Here is one possible sample run of the program:

Enter the hourly rate in dollars: 6 Enter the start time: 11 AM Enter the end time: 6 PM The babysitter worked 7 hours and earned $42. 

Hint: To get the correct formatting for the amount earned (with the $ directly before the number and the period directly after it), you will need to use string concatenation. If necessary, you can convert a number into a string by using the str function.

Additional guidelines and requirements:

You may assume that the values entered by the user are valid, and thus you do not need to perform any checking for problematic values.

Test your program on a variety of inputs to make sure that you dont have any logic errors in your code.

Include comments at the top of the module file that contain your name and a description of the program. In addition, you should use good programming style selecting descriptive variable names, inserting blank lines between logical parts of your program, and adding comments where necessary to explain what your code does.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!