Can't change a string back to an integer in Python 3 -
def get_time(): start_time = str(input("please enter time started working (hh:mm) ")) if ":" in start_time: h1, m1 = start_time.split(":") else: h1 = int(start_time) m1 = " " if h1 < 8: print("you can't start working until 08:00.") elif h1 > 23: print("you can't work past 24:00 (midnight) ") end_time = str(input("please enter time stopped working (hh:mm) ")) get_time() here's code program i'm making take in times babysitted. i'm having trouble turning string numbers integer. error:
file "/applications/python 3.4/babysitting.py", line 10, in get_time if h1 < 8: typeerror: unorderable types: str() < int() why isn't h1 = int(start_time) working?
why isn't
h1 = int(start_time)working?
that line isn't being executed @ when have : character in input:
if ":" in start_time: h1, m1 = start_time.split(":") else: h1 = int(start_time) m1 = " " the int(start_time) executed only when there no : in input, when if test false.
separate splitting , integer conversion:
h1 = start_time if ":" in start_time: h1 = start_time.split(":")[0] h1 = int(h1)
Comments
Post a Comment