Help me, please!


Hi everyone!
I was coding a simple program for school using the codes in the first part of the lesson "practice makes perfect".
I have Python 3.4.2 on my pc.When I'm writing this code, it's throwing an error:

def digit_sum(n):
            for a in n:
            print('The sum of the digits is ',b)

Traceback (most recent call last):
  File "E:/folder/program", line 57, in <module>
  File "E:/folder/", line 54, in digit_sum
ValueError: invalid literal for int() with base 10: '.'

I'm really stuck and I need to prepare it for tomorrow!So please tell me what to do.


Make this variable a list and your code should work :slight_smile:


Thank you.It is working now.I think the problem was with another part of the code.


No that was the issue, hence the error,


Earlier in this code, I had written:

num=float(raw_input("write your number."))

and so, num was a float.For example, if I enter 74, the float is 74.0 and when it would be converted to string, it would be "74.0".and when it goes throgh:

for a in n:

and ' . '(dot) can't be converted to int.
So I converted 'num' to int and the problem was solved.
Thank you for your help^^


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