Weird error for a simple exercise with loop


#1



https://www.codecademy.com/fr/courses/python-intermediate-fr-FR-py0yl/0/4?curriculum_id=5370f030fed2a866a2000001

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


#2

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

#3

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 //.


#4

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