1 Star 0 Fork 0

mamh-mixed/python-cookbook

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
convert_time.py 783 Bytes
一键复制 编辑 原始数据 按行查看 历史
slowy07 提交于 2022-01-30 09:33 +08:00 . refactor: clean code
from __future__ import print_function
# Created by sarathkaul on 12/11/19
def convert_time(input_str):
# Checking if last two elements of time
# is AM and first two elements are 12
if input_str[-2:] == "AM" and input_str[:2] == "12":
return "00" + input_str[2:-2]
# remove the AM
elif input_str[-2:] == "AM":
return input_str[:-2]
# Checking if last two elements of time
# is PM and first two elements are 12
elif input_str[-2:] == "PM" and input_str[:2] == "12":
return input_str[:-2]
else:
# add 12 to hours and remove PM
return str(int(input_str[:2]) + 12) + input_str[2:8]
if __name__ == "__main__":
input_time = input("Enter time you want to convert: ")
print(convert_time(input_time))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mamh-mixed/python-cookbook.git
git@gitee.com:mamh-mixed/python-cookbook.git
mamh-mixed
python-cookbook
python-cookbook
master

搜索帮助