Reputation: 35
Trying to find the total time worked in this. Cant seem to figure out what I have wrong.
#Problem 3, Python, Extra Credit
hourStart = int(input("Please enter the hour that Jimmy started work."))
minStart = int(input("Please enter the minute on the hour that Jimmy started work."))
hourEnd = int(input("Please enter the hour that Jimmy ended work."))
minEnd = int(input("Please enter the minute on the hour that Jimmy ended work."))
lunchHourStart = int(input("Please enter that hour that Jimmy started lunch."))
lunchMinStart = int(input("Please enter the minute on the hour that Jimmy started lunch."))
lunchHourEnd = int(input("Please enter the hour that Jimmy ended his lunch break."))
lunchMinEnd =int(input("Please enter the minute on the hour that Jimmy ended his lunch break."))
start = hourStart * 60 + minStart
end = hourEnd * 60 + minEnd
totalTime = end + start
lunchStart = lunchHourStart * 60 + lunchMinStart
lunchEnd = lunchHourEnd * 60 + lunchMinEnd
lunchTime = lunchEnd - lunchStart
timeWorked = (totalTime - lunchTime) * 60
hoursWorked = int(timeWorked)
min = (timeWorked - hoursWorked) * 60
print (min)
Upvotes: 0
Views: 44
Reputation: 87144
Total time should be calculated as
totalTime = end - start
All durations are in minutes, so the following is already in minutes, and does not need to be multiplied by 60:
timeWorked = (totalTime - lunchTime)
Now you have timeWorked
in minutes, so in hours that is:
hoursWorked = int(timeWorked / 60)
and the minutes would be the remainder:
minutesWorked = timeWorked % 60
The last 2 statements could be replaced with divmod()
:
hoursWorked, minutesWorked = divmod(timeWorked, 60)
Upvotes: 2