fork download
  1. def commas(data):
  2. place = 0
  3. commas = []
  4. while place < len(data):
  5. if data[place] == ",":
  6. commas.append(place)
  7. place += 1
  8. return commas
  9.  
  10. def getLocation(data):
  11. set = commas(data)
  12. location = int(data[:set[0]])
  13. return location
  14.  
  15. def convertTime(value):
  16. place = value
  17. letters = ["A", "B", "C", "D", "E", "F", "G", "H"]
  18. numbers = range(10, 18)
  19. location = 0
  20. while location < len(letters):
  21. if letters[location] == value:
  22. place = numbers[location]
  23. location += 1
  24. place = int(place)
  25. total = 30 * place
  26. total += 510
  27. hours = total / 60
  28. minutes = total % 60
  29. time = [hours, minutes]
  30. return time
  31.  
  32. def findStart(data):
  33. set = commas(data)
  34. start = data[set[0] + 1:set[1]]
  35. return convertTime(start.strip())
  36.  
  37. def findEnd(data):
  38. set = commas(data)
  39. end = data[set[1] + 1:]
  40. return convertTime(end.strip())
  41.  
  42. def hours(start, end):
  43. startMin = 60 * start[0] + start[1]
  44. endMin = 60 * end[0] + end[1]
  45. difference = endMin - startMin
  46. hours = difference / 60.0
  47. return hours
  48.  
  49. def price(location, hours):
  50. price = 0
  51. if location in range(1, 10):
  52. price = 10 * hours
  53. elif location in range(10, 20):
  54. if hours <= 4:
  55. price = 8 * hours
  56. else:
  57. price = 12 * hours - 16
  58. elif location in range(20, 30):
  59. if hours <= 4:
  60. price = 12 * hours
  61. else:
  62. price = 24 * hours - 48
  63. return price
  64.  
  65. def main():
  66. datas = []
  67. locations = []
  68. hour = []
  69. prices = []
  70. intPrices = []
  71. worker = 0
  72. while worker < 4:
  73. datas.append(raw_input())
  74. locations.append(getLocation(datas[worker]))
  75. hour.append(hours(findStart(datas[worker]), findEnd(datas[worker])))
  76. prices.append(price(locations[worker], hour[worker]))
  77. intPrices.append(prices[worker])
  78. prices[worker] = "$" + str(prices[worker]) + "0"
  79. worker += 1
  80. worker = 0
  81. while worker < 4:
  82. print prices[worker]
  83. worker += 1
  84. worker = 0
  85. sumOfPrices = sum(intPrices)
  86. sumOfPrices = "$" + str(sumOfPrices) + "0"
  87. print sumOfPrices
  88.  
  89. main()
Success #stdin #stdout 0.01s 7856KB
stdin
3, 9, H
17, 1, E
20, 5, G
15, 2, 8
stdout
$40.00
$62.00
$84.00
$24.00
$210.00