Question

WITH THE LATEST VERSION OF PYTHON: A babysitter charges $2.50 an hour until 9:00 PM when...

WITH THE LATEST VERSION OF PYTHON:

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 a starting time and ending time in hours and minutes and calculates the total babysitting bill. You may assume that the starting and ending times are in a single 24-hour period. Partial hours should be appropriately prorated.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code in image:

Code:

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)

  
  

  
Output:

Here I divided the program into three conditions

(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.

Add a comment
Know the answer?
Add Answer to:
WITH THE LATEST VERSION OF PYTHON: A babysitter charges $2.50 an hour until 9:00 PM when...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python 3 beginner top question please In Boilerville, a bicycle can be rented between 8:00 am...

    python 3 beginner top question please In Boilerville, a bicycle can be rented between 8:00 am unti 9.0 0 are prot hour from 8:00 am until 3:30 pm. From 3:30 pm until 9:00o Partial ho bike, and they do not rent bikes before 8:00 am or Define a function named q50 that prm. The charge for each bike is $1 75p pm the rate is $2.50 an hour. These rates are per after 9:00 pm. Partial hours accepts the number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT