-
-
Save Lewiscowles1986/13f1f59035f80e73fd4cdc48e7fbc269 to your computer and use it in GitHub Desktop.
talking-clock python
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
twelve | |
one | |
two | |
three | |
four | |
five | |
six | |
seven | |
eight | |
nine | |
ten | |
eleven |
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
O' one | |
O' two | |
O' three | |
O' four | |
O' five | |
O' six | |
O' seven | |
O' eight | |
O' nine | |
ten | |
eleven | |
twelve | |
thirteen | |
fourteen | |
fifteen | |
sixteen | |
seventeen | |
eighteen | |
nineteen | |
twenty | |
twenty one | |
twenty two | |
twenty three | |
twenty four | |
twenty five | |
twenty six | |
twenty seven | |
twenty eight | |
twenty nine | |
thirty | |
thirty one | |
thirty two | |
thirty three | |
thirty four | |
thirty five | |
thirty six | |
thirty seven | |
thirty eight | |
thirty nine | |
fourty | |
fourty one | |
fourty two | |
fourty three | |
fourty four | |
fourty five | |
fourty six | |
fourty seven | |
fourty eight | |
fourty nine | |
fifty | |
fifty one | |
fifty two | |
fifty three | |
fifty four | |
fifty five | |
fifty six | |
fifty seven | |
fifty eight | |
fifty nine |
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
def hours_int_to_text(i): | |
hours = [] | |
with open("data/hour_units.txt", "r") as f: | |
hours = f.read().splitlines() | |
return hours[i] | |
def minutes_int_to_text(i): | |
minutes = [] | |
with open("data/minute_units.txt", "r") as f: | |
minutes = f.read().splitlines() | |
return minutes[i] | |
def talk(time): | |
t = time.split(":") | |
H = int(t[0]) | |
h = H % 12 | |
m = int(t[1]) | |
a = 'am' if H < 12 else 'pm' | |
A = a.upper() | |
return " ".join([ | |
"It's", | |
hours_int_to_text(h), | |
minutes_int_to_text(m), | |
A]).replace(" ", " ") |
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 talkingclock import talk | |
import unittest | |
class TestOutput(unittest.TestCase): | |
def test_one_fifteen_am(self): | |
self.assertEqual(talk("01:15"), "It's one fifteen AM") | |
def test_eleven_fourtyseven_am(self): | |
self.assertEqual(talk("11:47"), "It's eleven fourty seven AM") | |
def test_twelve_am(self): | |
self.assertEqual(talk("00:00"), "It's twelve AM") | |
def test_two_fiftytwo_pm(self): | |
self.assertEqual(talk("14:52"), "It's two fifty two PM") | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment