Code Project - time cauculator : Need help

Right now I am trying to learn programming. So far I have not been successful in completing any task. For time calculator project this is my code:

def add_time(start, duration):
  timevar =[]
  duvar =[]
  timevar = start.replace(" ",":").split(":")
  duvar = duration.split(":")
  #convert PM to 24 hour
  if timevar[2] == "PM":
    convar = int(timevar[0]) + 12
  else: convar = int(timevar[0])
  #calculate minute and convert minute
  Total_minute = int(timevar[1]) + int(duvar[1])
  if Total_minute >60 :
    Extra_hour = 1
    Total_minute = Total_minute - 60
  else: Extra_hour = 0
  # calculate hour and convert hour
  Total_hour = convar + int(duvar[0]) + int(Extra_hour)
  n_day = float((Total_hour/24) - 1)
  if n_day <0 : p_day=" "
  elif n_day >0 and n_day <1 : p_day= "(next day)"
  else: p_day = f"({int(n_day)+1} days later)"
  restime = Total_hour % 24
  if restime >0.5 : ampm = "PM"
  else: ampm = "AM"
  if Total_hour > 24:
    con_hour = Total_hour - ((int(n_day)+1)*24)
  else: con_hour = Total_hour
  if con_hour > 12:
    Print_hour = con_hour - 12
  else: Print_hour = con_hour
  print (f"{Print_hour}:{Total_minute:02d} {ampm} {p_day}")

and when I run the program this is my result

1:08 PM (next day)
3:07 PM
F6:18 PM (20 days later)
FE2:45 PM (next day)
F5:01 PM
F12:05 PM
F5:42 PM
FE2:59 PM (next day)
FE0:04 AM (2 days later)

plus 8 failures and 4 errors.

While I suspect that 8 failures is more of a wrong calculation on my side, I am curious on why my 2nd line result in none and there are F or FE in front of my answers from line 3 and afterwards. Any suggestion or guidance would be appreciated. Thank you in advance.

Hey there :slightly_smiling_face:

Could you post a link to the lesson? It makes debugging so much easier.

Hi, this is the link for assignment.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.