LoginSignup
0
0

More than 5 years have passed since last update.

Checkio sum を使用しないでリスト内の要素を足す方法

Posted at

久々に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)
0
0
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0