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
2,085 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,840 points

Related Questions In Python

+2 votes
10 answers

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

The following are totally acceptable in python: passing ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,560 points
409,220 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,770 points
2,890 views
0 votes
1 answer

invalid literal for int() with base 10

In order to solve this problem, one ...READ MORE

answered Feb 8, 2022 in Python by Soham
• 9,710 points
1,232 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,560 points
1,419 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 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,790 points
4,069 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,840 points
7,824 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,840 points
888 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP