【发布时间】:2019-09-14 10:03:35
【问题描述】:
所以我正在尝试使用 Python 编写一个程序,该程序将在一定时间后发送文本提醒。我正在尝试检查时间是否在现实范围内(即一天不超过或少于 24 小时),但在尝试比较它们时出现错误。我无法比较从字符串连接的整数。
dur = input("How long do you want to wait (EX: HHMMSS): ")
hours = int(dur[0:1])
minutes = int(dur[2:3])
seconds = int(dur[4:5])
print(hours)
print(minutes)
print(seconds)
for n in range(0, LOOP):
if(count == 0):
# Check if hours is realistic
if(hours > 0 and hours < 24 and str(hours[0]) == 0):
hours = hours[1]
count += 1
我收到一个 TypeError 说 > 在 str 和 int 的实例之间不支持。由于我无法将它们与>或
【问题讨论】:
-
顺便说一句,要获取前两个字符,您需要
[0:2]或只需[:2]。正确的范围是[0:2]、[2:4]和[4:6]。
标签: python string int comparison concatenation