```n=int(input())

sum=0

for i in range(0,n):
x=int(input())
sum=sum+x
print(sum)

Traceback (most recent call last):
File "Solution.py", line 4, in <module>
x=int(input())
ValueError: invalid literal for int() with base 10: '1 2 3 4 10 11'```
Jul 24, 2020 in Python
edited Jul 24, 2020 2,390 views

## 2 answers to this question.

Hi@shrood,

If you are trying to sum the natural no., then you don't require to write the input function two times. Otherwise, it will ask you in every loop. You can use the below code.

```n=int(input())
sum=0
for i in range(0,n):
sum=sum+i
print(sum)```
• 95,460 points
Hi!

not the natural numbers sir!

first input  "n"  represents the number of array

and then taking n numbers as input in the for loop

and sum of all those numbers

Yes, I understood. But think once. According to your code, you are asking input inside the loop. So it will ask an input in every iteration. Try to analyze with a dry run. Take an example and try with pen and paper first.

oh ! understood

thanks a lot

Hello @shrood ,

If you are trying to find the sum of numbers entered by the user then your code is correct.
The error is because the IDE you are using might be taking all the input first and then executed your sciprt. so first enter all the inputs required and then exectute your script.

For example:

```5

4

1

3

2

5

15

```

Here n=5 and sum=15.

Tips: Try with diffrent IDE like pycharm(it will takes user input one at a time)

If you want to execute your script use this https://www.tutorialspoint.com/execute_python_online.php(Note: first give the value n and all the values entered by the user in stdin and in main.py paste your script)

Hope it helps!!
Thank you!!

• 82,840 points
yeah, it did

thanks a lot man!

## why do i get this error. (File "main.py", line 18 message = connectionSocket.recv(1024) ^ IndentationError: expected an indented block  ) and how to make it write

Hello, The error itself explain what's the problem.In ...READ MORE

## Python join: why is it string.join(list) instead of list.join(string)?

950down voteaccepted It's because any iterable can be ...READ MORE

## Python join: why is it string.join(list) instead of list.join(string)?

This is because join is a "string" ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

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

## Lowercase in Python

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