我有一个HackerRank(时间增量)问题。我的函数似乎运行得很好,但是,当我运行代码时,它只输出一个值,而应该输出多个值。
样本输入:
2
Sun 10 May 2015 13:54:36 -0700
Sun 10 May 2015 13:54:36 -0000
Sat 02 May 2015 19:54:36 +0530
Fri 01 May 2015 13:54:36 -0000
预期输出:
25200
88200
我的代码:
#!/bin/python3
import math
import os
import random
import re
import sys
import datetime as dt
# Complete the time_delta function below.
def time_delta(t1, t2):
t1 = t1.split()
t2 = t2.split()
day1 = str(t1[0] + ' ' + t1[2] + ' ' + t1[1] + ' ' + t1[3] + ' ' + t1[4] + ' ' + t1[5])
day2 = str(t2[0] + ' ' + t2[2] + ' ' + t2[1] + ' ' + t2[3] + ' ' + t2[4] + ' ' + t2[5])
datetime_t1 = dt.datetime.strptime(day1, '%a %b %d %Y %H:%M:%S %z')
datetime_t2 = dt.datetime.strptime(day2, '%a %b %d %Y %H:%M:%S %z')
time_diff = datetime_t1 - datetime_t2
print(int(time_diff.total_seconds()))
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input())
for t_itr in range(t):
t1 = input()
t2 = input()
delta = time_delta(t1, t2)
fptr.write(delta + '\n')
fptr.close()
我们将不胜感激!
答案 0 :(得分:0)
您解析这些时间的格式应为train['VOTES'][((train['VOTES'].isna()) & (train['CITY'].isin(['A','C'])))]=train['VOTES'].loc[((~train['VOTES'].isna()) & (train['CITY'].isin(['A','C'])))].astype(int).mean(axis=0)
:
'%a %d %b %Y %H:%M:%S %z'