Tell us what’s happening:
Describe your issue in detail here.
so i’ve been able to build the function “add_time” for the time calculator project. i’m having an issue incorporating the 3rd parameter which is optional. the issue i have is how to check for the 3rd parameter, which represents days of the week and also where do i nest whatever conditional statement i use to check for the current day of the week if it’s provided.
thanks
Your code so far
def add_time(start, duration):
days=[“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”];
starthr=start.split(":")[0]
s=start.split(":")[1]
startmin=s.split(" “)[0]
dhour=duration.split(”:")[0]
dmin=duration.split(":")[1]
AMPM=s.split(" “)[1]
newtime=”"
nhr=int(starthr)+int(dhour)
nmin=int(startmin)+int(dmin)
if nhr<24:
if nhr>12 and nmin>=60 and AMPM==“AM”:
nhr=nhr-11
nmin=nmin-60
if len(str(nmin))==1:
newtime=str(nhr)+":"+“0”+str(nmin)+" “+“PM”
else:
newtime=str(nhr)+”:"+str(nmin)+" "+“PM”
elif nhr>12 and nmin<60 and AMPM=="AM":
nhr=nhr-12
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"PM"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"PM"
elif nhr<12 and nmin<60 and AMPM=="PM":
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"AM"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"AM"
elif nhr<12 and nmin>=60 and AMPM=="AM":
nhr=nhr+1
nmin=nmin-60
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"PM"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"PM"
elif nhr>12 and nmin>=60 and AMPM=="PM":
nhr=nhr-11
nmin=nmin-60
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"AM" +" (next day)"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"AM"
elif nhr<12 and nmin>=60 and AMPM=="PM":
nhr=nhr+1
nmin=nmin-60
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"AM"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"AM"
elif nhr<12 and nmin<60 and AMPM=="AM":
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"PM"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"PM"
elif nhr>12 and nmin<60 and AMPM=="PM":
nhr=nhr-12
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"AM"+" (next day)"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"AM"+" (next day)"
elif nhr==12 and nmin>=60 and AMPM=="AM":
if len(str(nmin))==1:
newtime=str(nhr+1)+":"+"0"+str(nmin-60)+" "+"PM"
else:
newtime=str(nhr+1)+":"+str(nmin-60)+" "+"PM"
elif nhr==12 and nmin<60 and AMPM=="PM":
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"AM"+" (next day)"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"AM"+" (next day)"
elif nhr==12 and nmin>=60 and AMPM=="PM":
if len(str(nmin))==1:
newtime=str(nhr+1)+":"+"0"+str(nmin-60)+" "+"AM"+" (next day)"
else:
newtime=str(nhr+1)+":"+str(nmin-60)+" "+"AM"+" (next day)"
elif nhr==12 and nmin<60 and AMPM=="AM":
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"PM"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"PM"
elif nhr>24:
nhr=int(starthr)+(int(dhour)%24)
ndays=int(dhour)/24
if nhr>12 and nmin>=60 and AMPM=="AM":
nhr=nhr-11
nmin=nmin-60
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"PM " + str(int(ndays+1))+" days later"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"PM " + str(int(ndays+1))+" days later"
elif nhr>12 and nmin<60 and AMPM=="AM":
nhr=nhr-12
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"PM " + str(int(ndays+1))+" days later"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"PM " + str(int(ndays+1))+" days later"
elif nhr<12 and nmin<60 and AMPM=="PM":
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"AM " + str(int(ndays+1))+" days later"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"AM " + str(int(ndays+1))+" days later"
elif nhr<12 and nmin>=60 and AMPM=="AM":
nhr=nhr+1
nmin=nmin-60
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"PM " + str(int(ndays+1))+" days later"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"PM " + str(int(ndays+1))+" days later"
elif nhr>12 and nmin>=60 and AMPM=="PM":
nhr=nhr-11
nmin=nmin-60
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"AM " +" (next day)" + str(int(ndays+1))+ " days later"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"AM " + str(int(ndays+1))+ " days later"
elif nhr<12 and nmin>=60 and AMPM=="PM":
nhr=nhr+1
nmin=nmin-60
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"AM " + str(int(ndays+1))+" days later"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"AM " + str(int(ndays+1))+" days later"
elif nhr<12 and nmin<60 and AMPM=="AM":
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"PM " + str(int(ndays+1))+" days later"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"PM " + str(int(ndays+1))+" days later"
elif nhr>12 and nmin<60 and AMPM=="PM":
nhr=nhr-12
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"AM "+" (next day)" + str(int(ndays+1))+" days later"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"AM "+" (next day)" + str(int(ndays+1))+" days later"
elif nhr==12 and nmin>=60 and AMPM=="AM":
if len(str(nmin))==1:
newtime=str(nhr+1)+":"+"0"+str(nmin-60)+" "+"PM " + str(int(ndays+1))+" days later"
else:
newtime=str(nhr+1)+":"+str(nmin-60)+" "+"PM " + str(int(ndays+1))+" days later"
elif nhr==12 and nmin<60 and AMPM=="PM":
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"AM "+" (next day)" + str(int(ndays+1))+" days later"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"AM "+" (next day)" + str(int(ndays+1))+" days later"
elif nhr==12 and nmin>=60 and AMPM=="PM":
if len(str(nmin))==1:
newtime=str(nhr+1)+":"+"0"+str(nmin-60)+" "+"AM "+" (next day)" + str(int(ndays+1))+" days later"
else:
newtime=str(nhr+1)+":"+str(nmin-60)+" "+"AM "+" (next day)" + str(int(ndays+1))+" days later"
elif nhr==12 and nmin<60 and AMPM=="AM":
if len(str(nmin))==1:
newtime=str(nhr)+":"+"0"+str(nmin)+" "+"PM " + str(int(ndays+1))+" days later"
else:
newtime=str(nhr)+":"+str(nmin)+" "+"PM " + str(int(ndays+1))+" days later"
return newtime
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36 GLS/90.10.4909.10
Challenge: Time Calculator
Link to the challenge: