Daily Coding Challenge: Wake-Up Alarm
A few weeks ago I started following the python certification offered at the platform freeCodeCamp (https://www.freecodecamp.org/). They propose daily coding challenge, and I've solved a few of them.
Today's challenge is the following:
Given a string representing the time you set your alarm and a string representing the time you actually woke up, determine if you woke up early, on time, or late.
Both times will be given in "HH:MM" 24-hour format. Return:
"early" if you woke up before your alarm time. "on time" if you woke up at your alarm time, or within the 10 minute snooze window after the alarm time. "late" if you woke up more than 10 minutes after your alarm time. Both times are on the same day.
My solution
def transform(string): hours = int(string[0:2]) minutes = round(int(string[-2:]) / 60, 2) return hours + minutes def alarm_check(alarm_time, wake_time): alarm_time = transform(alarm_time) wake_time = transform(wake_time) if alarm_time - wake_time < -0.17: return "late" if -0.17 <= alarm_time - wake_time <= 0.17: return "on time" if alarm_time - wake_time > 0.17: return "early"