寻找总时间

时间:2014-09-15 03:42:48

标签: python python-3.3

试图找到在此工作的总时间。似乎无法弄清楚我的错误。

#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)

1 个答案:

答案 0 :(得分:2)

总时间应计算为

totalTime = end - start

所有持续时间均以分钟为单位,因此以下内容已在几分钟内完成,无需乘以60:

timeWorked = (totalTime - lunchTime)

现在你有几分钟的timeWorked,所以在几个小时内就是:

hoursWorked = int(timeWorked / 60)

并且会议记录将是剩余时间:

minutesWorked = timeWorked % 60

最后2个陈述可以替换为divmod()

hoursWorked, minutesWorked = divmod(timeWorked, 60)