Weird error for a simple exercise with loop


The exercise is very simple, it is a sum of figures in a number, so i proceed like this.

"'int' object is not callable" error

But when i execute the same code in an other terminal (Python with unix terminal), it works.

def somme_chiffre(nombre):
    total = 0
    nombre = str(nombre)
    for chiffre in nombre:
        total += int(chiffre)
    return total


There is a bug in this lesson. A couple of workarounds have been contributed by members, @appylpye, @ionatan and @zeziba in the past. Here is one that you can paste at the bottom of your code...

def somme_chiffre(n):
    return somme_chiffre


Thanks you for your reply. I was pretty sure, it was a bug, but it was in case of the debugger force you to code in an other way (to think differently that with a string decomposition). Like the uses of modulo % and //.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.