質問:
配列内の数値の合計を返し、空の配列の場合は0を返します。13という数字は非常に不運なので、カウントされず、13の直後の数字もカウントされません。
私のコード:
def sum13(nums):
l = len(nums)
tot = 0
if l==0:
return 0
for x in range(l):
if nums[x]!=13:
if nums[x-1]!=13:
tot+=nums[x]
return tot
失敗している場所:
sum13([1, 2, 2, 1, 13]) should → 6, but my code is outputting 5
sum13([1, 2, 13, 2, 1, 13]) should → 4, but my code is outputting 3