久々にcheckioをやってみて、sumを使用しないでリスト内の要素を足して行く問題があった。
自分のコードができない理由が不明のため、メモとして保存しておく。
下記問題文
Our new calculator is censored and as such it does not accept certain words. You should try to trick by writing a program to calculate the sum of numbers.
Given a list of numbers, you should find the sum of these numbers. Your solution should not contain any of the banned words, even as a part of another word.
The list of banned words are as follows:
sum
import
for
while
reduce
Input: A list of numbers.
Output: The sum of numbers.
回答コード
scal = 0
def checkio(data):
global scal
if len(data) == 0:
return scal
else:
scal += data[0]
del data[0]
return checkio(data)