Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
More datetime module solution in Clear category for Sun Angle by nakanohito_piyo
import datetime
def sun_angle(time):
now = datetime.datetime.strptime(time, "%H:%M")
t_zero = datetime.timedelta(hours=6, minutes=0)
delta = now - t_zero
minutes = delta.hour*60 + delta.minute
if not 0 <= minutes <= 12*60:
return "I don't see the sun!"
angle = minutes * 0.25
if minutes%4 == 0:
return round(angle)
else:
return round(angle, 2)
if __name__ == '__main__':
print("Example:")
print(sun_angle("07: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!"
print("Coding complete? Click 'Check' to earn cool rewards!")
May 15, 2018
Comments: