Define a function, time(x,y), that takes time in hours and minutes rounds it to the nearest 5 minutes and expresses it as a word/string.
For example:
time(7,5) returns "five after seven"
time(7,13) returns "quarter after seven"
time(7,9) returns "ten after seven"
time(7,20) returns "twenty after seven"
time(7,24) returns "twenty five after seven"
time(7,30) returns "half past seven"
time(7,36) returns "twenty five to eight"
time(7,38) returns "twenty to eight"
time(7,45) returns "quarter to eight"
time(7,50) returns "ten to eight"
time(7,56) returns "five to eight"
time(12,00) returns "noon"
time(18,20) returns "twenty after six"
time(23,45) returns "a quarter to midnight"
My plan to code this was to use an array for the hours and if statements and append the minutes. I started with my code but I'm having troubles making it work
def time(h):
words=["midnight","one","two","three","four","five","six","seven","eight","nine","ten","eleven","noon"]
for n in range(len(words)):
h = (words[n])
return h
When I simply run just this code, it give me 'noon' every time. I know I am doing something wrong, can someone please help my fix this and give me a start in the right direction for the minutes.
Thanks
for n in range(len(words)):seems wrong. Tryreturn words[h]directly and see what happens.