Tell us what’s happening:
Hey campers,
I am doing this time calculator challenge and I get this error:
value error: not enough values to unpack (expected 2, got 1)
Also seems there are some flaws in the logic of my code:
def add_time(start, duration):
starting = start.split(" ")
num = starting[0]
form = starting[1]
starttime = num.split(':')
hours = starttime[0]
mins = starttime[1]
addedtime = duration.split(':')
addedhrs = addedtime[0]
addedmins = addedtime[1]
tothrs = hours + addedhrs
totmins = mins + addedmins
if(form == 'PM' or form == 'AM'):
count, totalhrs = get_count(tothrs),
days = get_days(tothrs)
exists = timeFormat(totmins)
if exists:
totalhrs = totalhrs + 1 # Edge case
if count != 0 and count % 2 != 0:
if form == "AM":
form = "PM"
else:
form = "AM"
if days != 0:
return '%s:%s %s (%s days left)' % (totalhrs, totmins, form , days)
else:
return '%s:%s %s' % (totalhrs, totmins, form)
def timeFormat(mins):
hr = False
if(mins > 60):
hr = True
return hr
def get_count(tothrs):
count = 0
while (tothrs > 12) :
tothrs = tothrs - 12
count = count + 1
return count, tothrs
def get_days(tothrs):
days = 0
while (tothrs > 24) :
tothrs = tothrs - 24
days = days + 1
return days
Challenge: Time Calculator
Link to the challenge: