【发布时间】:2015-07-07 20:39:40
【问题描述】:
def get_time():
start_time = str(input("Please enter the time you 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 the time you stopped working (hh:mm) "))
get_time()
这是我正在制作的一个程序的代码,用于记录有人照看孩子的时间。我无法将字符串数字转回整数。我得到错误:
File "/Applications/Python 3.4/babysitting.py", line 10, in get_time
if h1 < 8:
TypeError: unorderable types: str() < int()
为什么h1 = int(start_time) 不起作用?
【问题讨论】:
标签: python string python-3.x int