将形如 5D, 30s 的字符串转为秒

import sys
def convert_to_seconds(time_str):
    # write code here
    if 's' in time_str:
        return float(time_str[:-1])
    elif 'm' in time_str:
        return float(time_str[:-1]) * 60
    elif 'h' in time_str:
        return float(time_str[:-1]) * 3600
    elif 'd' in time_str:
        return float(time_str[:-1]) * 3600 *24
    elif 'D' in time_str:
        return float(time_str[:-1]) * 3600 *24

while True:
    line = sys.stdin.readline()
    line = line.strip()
    if line == '':
        break
    print(convert_to_seconds(line))

2020-04-24

posted @ 2020-04-24 23:16  CodeYaSuo  阅读(298)  评论(0编辑  收藏  举报