Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Split and compare tuples solution in Clear category for Sun Angle by pon.tu.correo.aca
def sun_angle(time):
"""
The function splits the time into a tuple of integers
compares the time to tuples reprensenting sunrise and sunset times
if time is in the correct range it calculated the angle of the sun
by subtracting 6 to the hours then multipliying by (180/12 = 15) and
multiplaying the minutes by (15/60 = 0.25) or of if time is outside
the range returns "I don't see the sun!"
"""
time = tuple(int(i) for i in time.split(':'))
if (6,0) <= time <= (18,0):
return ( (time[0] - 6) * 15 + (time[1]) * 0.25 )
else:
return "I don't see the sun!"
if __name__ == '__main__':
print("Example:")
print(sun_angle("7:00"))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert sun_angle("07:00") == 15
assert sun_angle("01:23") == "I don't see the sun!"
assert sun_angle("18:01") == "I don't see the sun!"
assert sun_angle("6:00") == 0
assert sun_angle("6:01") == .25
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 8, 2018
Comments: