154k views
0 votes
A babysitter charges $2.50 an hour until 9:00 PM when the rate drops to$1.75 an hour (the children are in bed). Write a program that accepts astarting time and ending time in hours and minutes and calculates the totalbabysitting bill. You may assume that the starting and ending times are ina single 24-hour period. Partial hours should be appropriately prorated.

User Popgalop
by
4.7k points

1 Answer

5 votes

Answer:

print("enter starting time hours")

st_hours=int(input()) #starting time hours

print("minutes")

st_minutes=int(input()) #starting time minutes

print("enter ending time hours")

et_hours=int(input()) #ending time hours

print("minutes")

et_minutes=int(input()) #ending time minutes

cost=2.50

if (st_hours<21 and et_hours>21): #if starting time is less than 21 and ending time is greater than 21

a_hours=et_hours-21

a_minutes=et_minutes #taking time after 21 from ending time ending time-21

time_minutes=60-st_minutes #converting all the time into minutes

time_hours=21-(st_hours+1)

time_hours=time_hours*60

time=time_hours+time_minutes

cost=(cost/60)*time

time=(a_hours*60)+a_minutes

cost=cost+(1.75/60)*time

print("cost=$",cost)

elif(st_hours>=21): #if starting time is greater than 21

time_hours=et_hours-(st_hours+1)

time_minutes=(60-st_minutes)+et_minutes #converting time into minutes

time=(time_hours*60)+time_minutes

cost=(1.75/60)*(time)

print("cost=$",cost)

elif(et_hours<=21): #if ending time is less than 21

time_hours=et_hours-(st_hours+1)

time_minutes=(60-st_minutes)+et_minutes

time=(time_hours*60)+time_minutes

cost=(2.50/60)*time

print("cost=$",cost)

Step-by-step explanation:

This is a conditional program, the conditions applied are if and else if.

The resultant output was gotten using this three steps:

(1) If starting time is less than 21 and ending time is greater than 21

Then I converted the time into minutes before 21

ex:- 8:30

21-9= 12*60= 720 + 30 = 750

Then I calculated the bill.

750 * (2.50 / 60)

Then I converted the time after 21 and then calculated the bill and printed it.

(2)If starting time is greater than 21

Converted time into minutes and multiplied it with (1.75 / 60) to get the bill.

(3) If ending time is less than 21

Converted time into minutes and multiplied it with (2.50 / 60) to get the bill.

Please check attachment for program code screenshot.

A babysitter charges $2.50 an hour until 9:00 PM when the rate drops to$1.75 an hour-example-1
User Jacob Macallan
by
4.5k points