Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Avoid Magical Numbers / Mathematical / Twoliner solution in Clear category for Sun Angle by vinicius.rznd
def sun_angle(time):
# There´s a mathematical relation of 4x between the angle and the amount of minutes
# 12:00 - 06:00 = 6 hours * 60 minutes = 360 + 00 min = 360 / 4 = 90º
# 18:00 - 06:00 = 12hours * 60 minutes = 720 + 00 min = 720 / 4 = 180º
# To avoid "magical numbers" on your code
start_time_in_hours = 6
end_time_in_minutes = 721
minutes = time.split(":")
return ((int(minutes[0]) - 6) * 60 + int(minutes[1])) / 4 if int(minutes[0]) >= start_time_in_hours and ((int(minutes[0]) - 6) * 60 + int(minutes[1])) < end_time_in_minutes else "I don't see the sun!"
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert sun_angle("07:00") == 15
assert sun_angle("12:00") == 90
assert sun_angle("01:23") == "I don't see the sun!"
print("Coding complete? Click 'Check' to earn cool rewards!")
Dec. 22, 2020
Comments: