Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Straightforward solution in Clear category for Sun Angle by dankiktenko
from typing import Union
def sun_angle(time: str) -> Union[int, str]:
h, m = map(int, time.split(':'))
total_minutes = h * 60 + m
sunrise = 6 * 60
sunset = 18 * 60
if total_minutes < sunrise or total_minutes > sunset:
return "I don't see the sun!"
sunlight_duration = sunset - sunrise
return round((total_minutes - sunrise) * 180 / sunlight_duration, 2)
if __name__ == '__main__':
print("Example:")
print(sun_angle("07:00"))
print(sun_angle("12:15"))
# 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!"
print("Coding complete? Click 'Check' to earn cool rewards!")
June 13, 2022