def ifs(hour, minute):
if (int(hour) >= 6 and int(hour) <= 13) and (int(minute) >= 0 and int(minute) <= 59):
return “上午”
elif (int(hour) >= 14 and int(hour) <= 20) and (int(minute) >= 0 and int(minute) <= 59):
return “下午”
elif (int(hour) >= 5 and int(hour) <= 24) and (int(minute) >= 0 and int(minute) <= 59):
return “晚上”
while(True):
kind = bool(input(“是否为24小时制(是:1,否:直接回车):”))
if not (kind):
ma = input(“上午或下午:”)
while (ma != ‘上午’) and (ma != ‘下午’):
ma = input(“不符合要求,请重新输入:”)
hour = input(“时:”)
if kind:
while (int(hour) <= 0 or int(hour) > 24):
hour = input(“时(不符合要求重新输入):”)
else:
while (int(hour) <= 0 or int(hour) > 12):
hour = input(“时(不符合要求重新输入):”)
minute = input(“分:”)
while (int(minute) < 0) or (int(minute) >= 60):
minute = input(“分(不符合要求重新输入):”)
if kind:
ifss = ifs(int(hour), int(minute))
if int(hour) <= 12:
print('%d:%d' % (int(hour), int(minute)) + ifss)
else:
hour = int(hour) - 12
print('%d:%d' % (int(hour), int(minute)) + ifss)
else:
if ma == "上午":
print('%d:%d' % (int(hour), int(minute)))
else:
hour = int(hour) + 12
print('%d:%d' % (int(hour), int(minute)))