Created
July 9, 2017 20:42
-
-
Save isaiahdbarry/717310f9141c44fc5374cf4fbb31433b to your computer and use it in GitHub Desktop.
Solution to /r/dailyprogrammer challenge #321 (Python 3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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