Time Calculator- Logic in taking time from list

List

timing = [“3:00 PM”, “3:10”, “Monday”]

For Loop

for i, timer in enumerate(timing):

Trying to split only 3:00 PM from list

if " " in timing[i]:
hr1, term = timing[i].split(":")
min1, ender = term.split(" ") # This is OK

Trying to split only 3:00 from list

if " " not in timing[i]: #This line is selecting both second and third terms. The result must be second only
hr2, min2 = timing[i].split(":")

Trying to split Monday from list

if “:” not in timer[i]: # This is OK
day = timing[i]

Given your approach to the challenge, I would suggest you check for : first so as to eliminate the last element, and then check for " " in a nested loop. Of course if there is " ", then you are dealing with "3:00 PM" otherwise "3:10". Check the pseudo code below.

FOR each  Element in timing:
     IF Element has ":":
         IF Element has " ":
              Handle first element
         ELSE:
              Handle second element

if not allow to take variable out of it: :face_with_monocle: :face_with_monocle:

timing = [“3:00 PM”, “3:10”, “Monday”]

for i, timer in enumerate(timing):
if “:” in timing[i]:
if " " in timing[i]:
hr1, term = timing[i].split(":")
min1, ender = term.split(" “)
else:
hr2, min2 = timing[i].split(”:")
if “:” not in timing[i]:
day = timing[i]
print(day)
print(hr1)
print(min1)
print(hr2)
print(min2)

Error:

File “main.py”, line 19
print(hr1)
^
IndentationError: unindent does not match any outer indentation level

1 Like

The error message seems clear. You are getting an indentation error. I expected something like:

for time in timing:
  if ":" in time:
     if " " in time:
       print("With space >> " + time)
     else:
       print("No space >> " + time)
  else:
    print("No space and No ':' >> " + time)

Just replace the print statements with code depending on whatever it is you want to do with the different times.