-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththe_time_in_words.py
80 lines (69 loc) · 1.64 KB
/
the_time_in_words.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#https://www.hackerrank.com/challenges/the-time-in-words/problem?isFullScreen=true
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'timeInWords' function below.
#
# The function is expected to return a STRING.
# The function accepts following parameters:
# 1. INTEGER h
# 2. INTEGER m
#
def timeInWords(h, m):
# Write your code here
d = {
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
6: 'six',
7: 'seven',
8: 'eight',
9: 'nine',
10: 'ten',
11: 'eleven',
12: 'twelve',
13: 'thirteen',
14: 'fourteen',
15: 'quarter',
16: 'sixteen',
17: 'seventeen',
18: 'eighteen',
19: 'nineteen',
20: 'twenty',
21: 'twenty one',
22: 'twenty two',
23: 'twenty three',
24: 'twnety four',
25: 'twenty five',
26: 'twenty six',
27: 'twenty seven',
28: 'twenty eight',
29: 'twenty nine',
30: 'half'
}
if m == 0:
return d[h] + ' ' + 'o\' clock'
to = False
if m > 30:
m = 60 - m
h = h + 1
to = not to
if m == 1:
return f"{d[m]} minute {'to' if to else 'past'} {d[h]}"
if m == 15 or m == 30:
return f"{d[m]} {'to' if to else 'past'} {d[h]}"
else:
return f"{d[m]} minutes {'to' if to else 'past'} {d[h]}"
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
h = int(input().strip())
m = int(input().strip())
result = timeInWords(h, m)
fptr.write(result + '\n')
fptr.close()