Python时间24小时制和12小时制转换
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小時(shí)制(是:1,否:直接回車(chē)):”))
if not (kind):
ma = input(“上午或下午:”)
while (ma != ‘上午’) and (ma != ‘下午’):
ma = input(“不符合要求,請(qǐng)重新輸入:”)
hour = input(“時(shí):”)
if kind:
while (int(hour) <= 0 or int(hour) > 24):
hour = input(“時(shí)(不符合要求重新輸入):”)
else:
while (int(hour) <= 0 or int(hour) > 12):
hour = input(“時(shí)(不符合要求重新輸入):”)
minute = input(“分:”)
while (int(minute) < 0) or (int(minute) >= 60):
minute = input(“分(不符合要求重新輸入):”)
總結(jié)
以上是生活随笔為你收集整理的Python时间24小时制和12小时制转换的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【HTML】@weijinhai0101
- 下一篇: 【Python】Conda 安装 | G