I am new to learning python, I have been using source material for inspiration on how to code an alarm clock. I was wondering if anyone could explain a couple of the lines for me?
print("Set a time for the alarm (Ex. 06:30 or 18:30:00)")
while True:
alarm_input = input(">> ")
try:
alarm_time = [int(n) for n in alarm_input.split(":")]
if check_alarm_input(alarm_time):
break
else:
raise ValueError
except ValueError:
print("ERROR: Enter time in HH:MM or HH:MM:SS format")
# Convert the alarm time from [H:M] or [H:M:S] to seconds
seconds_hms = [3600, 60, 1] # Number of seconds in an Hour, Minute, and Second
alarm_seconds = sum(
[a*b for a, b in zip(seconds_hms[:len(alarm_time)], alarm_time)])
The while True is just referring to the check_alarm_input function I have which makes sure that the input is an actual time.
I am mainly confused by the line converting the alarm time to seconds,
I am not sure what a and b is and what is the purpose of the colon in:
zip(seconds_hms[:len(alarm_time)]
Any help appreciated!