invalid literal for int with base 10 in python

0 votes
# n= 10       
        # 1+2+3+4+5+6+7+8+9+10/10
   sum of digits of a number.    

Hi everyone. I am facing this error let me know where I am going wrong. How to resolve the issue.

i=1  
sum=0
num=0
print('enter the n value  of integers you want ')
n= eval(input())
print(type(sum))
print('enter 10 integers')

    
while i<=n:
    num = input()
    sum = sum+num
    i += 1
        
        
print('Avg is ', sum/n)
Nov 21, 2020 in Python by anonymous
• 120 points
121 views

1 answer to this question.

0 votes

Hello,

You can try this simple code:

def getSum(n): 

     

    sum = 0

    for digit in str(n):  

      sum += int(digit)       

    return sum

    

n = input("enter number")

print(getSum(n))
answered Nov 23, 2020 by Niroj
• 82,540 points

Related Questions In Python

+1 vote
10 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

Just for the record: >>> int('55063.000000') Traceback (most recent ...READ MORE

answered Aug 17, 2020 in Python by pakainfo
• 200 points
208,920 views
0 votes
1 answer

Error is "invalid literal for int() with base 10: ' ' "

This error is caused because we try ...READ MORE

answered Oct 15, 2020 in Python by Gitika
• 65,850 points
639 views
0 votes
1 answer

How should I write tests for Forms in Django with Python?

from django.tests import TestCase class MyTests(TestCase): ...READ MORE

answered Nov 20, 2018 in Python by Nymeria
• 3,520 points
239 views
0 votes
1 answer

How can I deal with python eggs for multiple platforms in one location?

Try virtualenv : http://pypi.python.org/pypi/virtualenv This helps you create isolated ...READ MORE

answered May 28, 2019 in Python by SDeb
• 13,250 points
107 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,719 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,310 views
0 votes
1 answer

Error:UnicodeDecodeError when reading CSV file in Pandas with Python

Hello @kartik, Try this: import pandas as pd df = ...READ MORE

answered Jun 15, 2020 in Python by Niroj
• 82,540 points
1,584 views
0 votes
1 answer

How to convert string to date in python with different algorithms ?

Hello @ pagarsach, You can convert a string to ...READ MORE

answered Jun 30, 2020 in Python by Niroj
• 82,540 points
138 views