Skip to content

Instantly share code, notes, and snippets.

@isaiahdbarry
Created July 9, 2017 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaiahdbarry/717310f9141c44fc5374cf4fbb31433b to your computer and use it in GitHub Desktop.
Save isaiahdbarry/717310f9141c44fc5374cf4fbb31433b to your computer and use it in GitHub Desktop.
Solution to /r/dailyprogrammer challenge #321 (Python 3)
from num2words import num2words
def timeAsString(time):
time = time.split(sep=":")
if int(time[0]) < 12:
timeofday = "AM"
else:
timeofday = "PM"
time[0] = int(time[0]) - 12
hour = int(time[0])
minute = int(time[1])
if hour == 00:
hour = 12
if num2words(minute) == "zero":
timeString = "It's {0} {1}".format(num2words(hour), timeofday)
else:
timeString = "It's {0} {1} {2}".format(num2words(hour), num2words(minute), timeofday)
return timeString
def main():
time = input("Please enter the time in 24 hour format: ")
print(timeAsString(time))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment