4. digit sum


#1

here is my code it seems to be correct but i still got an error message saying it failed on 434 as entry function saying : "'int' object is not callable" error.
can someone tell me what i ve done wrong
thanks for helping

def somme_chiffre (n):
total = 0
nstring = str(n)
for chiffre in nstring:
total = total + int(chiffre)
return total
print somme_chiffre (1234)


#2

@je22
I tried your code and it's Ok.

def somme_chiffre (n):
    total = 0
    nstring = str(n)
    for chiffre in nstring:
       total = total + int(chiffre)
    return total
print somme_chiffre (434)

Maybe you have to refresh your Browser

++++ reset of session *****************
under certain circumstances you can shoot your Browser in an
inconsistent state.

Therefor it is of an advantage to know that you have 2 reset facilities:

One is the use of the F5-key which does a refresh Browser

and

Two, select&copy your code
Then use the Reset Code button of the course-window,
then paste your code back in.

Addendum
General Notes:
Always refresh the browser after making corrections:
CTRL f5 ( if on Windows or Linux)
CMD r ( if on a MAC).
CTRL 0 to reset browser zoom


#3

The exercise, somme_chiffre, has a bug in its submission correctness test (SCT).

To pass, add this workaround to the end of your code ...

class str(object):
    def __add__(self, other):
        return True

#4

def digit_sum(n):
total=0
while n!=0:
s=n%10
total=total+s
n=n//10

return total

print digit_sum(1234)


#5

thans a lot for helping me


#6

def somme_chiffre (n):
total = 0
nstring = str(n)
for chiffre in nstring:
total = total + int(chiffre)
return total
print somme_chiffre (1111)

Please tell whats wrong with this code.. I am getting the output but error with the console.

error message:
Oops, try again. Does your digit_sum function take exactly one argument (a positive integer)? Your code threw a "cannot concatenate 'str' and 'int' objects" error.


#7

try this:

def somme_chiffre (n):
total = 0
nstring = str(n)
for chiffre in nstring:
total = total + int(chiffre)
return total
print somme_chiffre (434)
class str(object):
def add(self, other):
return True


#8

thank you :slight_smile:


#9

thank ereryboddy it's solved


#10

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