fork download
  1. import datetime
  2.  
  3. #Declarations:
  4. revisedTimeList = []
  5. timeRangeList = []
  6.  
  7. def inputTimes() :
  8. #Asks the user to input times, to be used as column headers, returns a list of strings representing time ranges.
  9.  
  10. studyTime = input("Please enter your study periods throughout the day (hh:mm hh:mm): ")
  11. timeList = studyTime.split()
  12. for time in timeList :
  13. structTime = datetime.datetime.strptime(time, "%I:%M%p")
  14. formattedTime = datetime.datetime.strftime(structTime, "%H:%M")
  15. revisedTimeList.append(formattedTime)
  16. timeRangeList = formatTimes(revisedTimeList)
  17. return timeRangeList
  18.  
  19. def formatTimes(revisedTimeList) :
  20. #Grouping individual times to create time ranges:
  21.  
  22. listOfTimes = revisedTimeList
  23. iteratorList = iter(listOfTimes)
  24. for time in iteratorList :
  25. timeRange = time + " - " + next(iteratorList)
  26. timeRangeList.append(timeRange)
  27. return timeRangeList
  28.  
  29. print(inputTimes())
Success #stdin #stdout 0.04s 10672KB
stdin
09:00AM 11:00AM 11:15AM 01:00PM 02:00PM 03:30PM 03:45PM 05:00PM 
stdout
Please enter your study periods throughout the day (hh:mm hh:mm): ['09:00 - 11:00', '11:15 - 13:00', '14:00 - 15:30', '15:45 - 17:00']