我一直在閱讀網站多年,今天是我的第一個問題。Google Foobar:提交解決方案時出現屬性錯誤
我被邀請在Google Foobar上玩Python搜索,因爲我在完成教程後測試了我發現的新知識。
當我提交我的 'solution.py' 我得到以下錯誤: AttributeError的第13行
此代碼運行在Eclipse
罰款這是代碼:
from itertools import permutations
import time
x, y, z = 3, 19, 19
values = [x, y, z]
perm_obj = permutations(values)
for v in perm_obj:
try:
if time.strptime(str(v), '(%m, %d, %y)'): #This is line 13
my_output.append(v)
except ValueError:
pass
編輯:perm_obj是itertools permutation
method的結果。
itertools.permutations(iterable, r=None)
編輯:我稍微更改了代碼以顯示perm_obj的外觀。我希望這有幫助。
代碼:
from itertools import permutations
from datetime import datetime
def answer(x, y, z):
values = [x, y, z]
perm_obj = permutations(values)
my_output = []
for v in perm_obj:
try:
print(v)
datetime.strptime(str(v), '(%m, %d, %y)')
my_output.append(v)
except ValueError:
pass
輸出:
(19, 19, 3)
(19, 3, 19)
(19, 19, 3)
(19, 3, 19)
(3, 19, 19)
(3, 19, 19)
請提供訴一個例子或perm_obj – ravigadila
拉維?我編輯了上面的原始文章 – Alex
如果你的代碼只有10行,第13行的錯誤必須在谷歌的代碼:) – 9000