Hello, I am trying to make a program to calculate the payment for a babysitter like this:
A babysitter charges $5 an hour until 9:00 p.m., at which point the rate drops to $3 an hour because the kids are in bed
# the start and end times are in a single 24-hour period
# the end time is after the start time
# the start time is between 7 a.m. and 10 p.m. inclusive
# the end time is no later than 3 a.m.

I think I've captured every condition, except that whenever I enter start hour before 9pm(21) and end hour after mid-night, 3am...I would get a negative result.

This program calculate the babysitter's wage based on 24 hour
Enter the start hour:  14
Enter the end hour:  2
----------------------
The payment is:  -60 dollars

This is my program, please help! thanks!

# This program calculates the babysitter's wage.
 
print "This program calculate the babysitter's wage based on 24 hour"
start = input("Enter the start hour:  ")
end = input("Enter the end hour:  ")
 
if start <= 21 and end <= 21: # if start before and end before 9pm.
        payment =(end - start)*5
elif start <= 21 and end <= 3: # if start before 9pm and end after midnight but before 3am.
        before = 21 - start
        after = (24 + end)- 21
        payment = 5* before + 3* after
elif start <= 21 and end >= 21:    # if start before 9pm and end before midnight.
        before = 21 - start
        after =  end - 21
        payment = 5* before + 3*after
if start >= 21 and end >= 21: # if start after 9pm and end before midnight
        payment = 3*(24 - end)
elif start >= 21 and end <= 3: # if start after 9pm and end after midnight but before 3am
        payment = 3*((24 + end)-21)
 
 
print "----------------------"
print "The payment is: ",payment, "dollars"

Edited 7 Years Ago by rociel: n/a

IDLE 2.6.2      
>>> start = 14
>>> end = 2
>>> if start <= 21 and end <= 21: # if start before and end before 9pm.
	payment =(end - start)*5

	
>>> print "The payment is: ",payment, "dollars"
The payment is:  -60 dollars
>>> if start <= 21 and end <= 21: # if start before and end before 9pm.
	payment =(start - end)*5

	
>>> print "The payment is: ",payment, "dollars"
The payment is:  60 dollars
>>>
This article has been dead for over six months. Start a new discussion instead.