我该如何处理这个过程?假设有人输入“3:5”,我应该能够得到输出“3:05 AM”。或者如果有人输入“00:00”,我应该输入“12:00 AM”。我意识到,如果时间格式简单地输入为“h h mm”,那么实现这一点的方法太多了,但是输入的范围可以是“h:m”、“hh:m”、“hh:m”和“hh:mm”。所以这是很有情境性的。def timeConvert():
miliTime = int(input("Enter a time in hh:mm (military) format: "))
miliTime.split(":")
if len(miliTime) == 3:
hours = miliTime[0]
minutes = miliTime[2]
if hours < 0:
print("Hours can't be less than 0.")
elif len(miliTime) == 4:
if miliTime[0:2] >= 10:
hours = militime[0:2]
minutes = militime[3]
if minutes < 0:
print("Minutes can't be less than 0.")
if minutes < 10:
minutes = 0 + minutes
else:
hours = miliTime[0]
minutes = militime[2:]
if minutes >= 60:
print("Too big of a number for minutes.")
else:
hours = miliTime[0:2]
minutes = miliTime[3:]
setting = AM
if hours > 12:
setting = PM
hours -= 12
print(hours + ":" + minutes + setting)
timeConvert()