假設某個停車場的費率是停車 2 小時以內,每半小時 30 元,超過 2 小時,但未滿 4 小時的部分,每半小時 40 元,超過 4 小時以上的部分,每半小時 60 元。未滿半小時的部分不計費。
請撰寫程式,輸入起始停車時間和結束停車時間,計算共需繳多少費用。
==================================================================
==================================================================import datetime import time def getMinuteDelta(startTime, endTime): if startTime > endTime: return 0 # convert to datetime y,m,d,H,M,S = startTime[0:6] dataTimea=datetime.datetime(y,m,d,H,M,S) y,m,d,H,M,S = endTime[0:6] dataTimeb=datetime.datetime(y,m,d,H,M,S) # compare datetime and convert to minute secondDelta = (dataTimeb-dataTimea).seconds dayDelta = (dataTimeb - dataTimea).days minuteDelta = dayDelta * (24 * 60) + round(secondDelta / 60) return minuteDelta def calculateMoney(time): time = divmod(time, 30) totalMondy = 0 if time[0] <= 4: totalMondy += time[0] * 30 elif time[0] <= 8: totalMondy += 4 * 30 + (time[0] - 4) * 40 else: totalMondy += 4 * 30 + 4 * 40 + (time[0] - 8) * 60 return totalMondy startTime = input('Please input start time (e.g YYYY-MM-DD hh:mm:ss) :') endTime = input('Please input end time (e.g YYYY-MM-DD hh:mm:ss) : ') dateFormat = '%Y-%m-%d %H:%M:%S' try: # convert input to time format minuteDelta = getMinuteDelta(time.strptime(startTime, dateFormat), time.strptime(endTime, dateFormat)) except ValueError: print("[Error #1] Wrong Format") else: print('total: $%d' %(calculateMoney(minuteDelta)))
執行結果:
Please input start time (e.g YYYY-MM-DD hh:mm:ss) :2017-01-01 10:23:00
Please input end time (e.g YYYY-MM-DD hh:mm:ss) : 2017-01-01 15:20:00
total: $340
man titanium bracelet - Titanium Art
回覆刪除The man-totanium-art wrist bracelet for sale at The Titsanium Art Gallery trex titanium headphones in Austin, Texas. View titanium daith jewelry our collection of titanium grades 1839 premium titanium pan products mens titanium rings that are made