Python Time Calculator

Tell us what’s happening:

Learner is instructed to not import any library. I do not agree for this assessment to be made without any single module not even regex. It will be bunch of lines which could be resumed in few lines. start and duration should be correctly and cleanly split. Actually I was able to add time using regex and numpy like the following.

PS: recently I successfully finished Google IT Automation with Python Professional Certificate and when the learner must do pure python assessment, it should not be such insane one like this time calculator.

I quit this assessment. Regards.

``````import re

import numpy as np

elems1 = re.split(r"\s", time)

elems2 = re.split(r":", elems1[0])

elems2.append(elems1[1])

elems3 = re.split(r":", duration)

remainder_from_minutes = int(np.floor((int(elems2[1]) + int(elems3[1]))/60))

resH = (int(elems2[0]) + int(elems3[0]))%24 + remainder_from_minutes

resM = (int(elems2[1]) + int(elems3[1]))%60

am_or_pm = elems2[2] if int(resH/12)%2==0 else chr(145-ord(elems2[2][0])) + "M"

return str(resH).rjust(2,"0") + ":" + str(resM).rjust(2,"0") + " " + str(am_or_pm)

``````

output

``````11:55 AM
12:10 AM
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 Edg/85.0.564.63`.

Challenge: Time Calculator