78466/why-is-it-showing-this-error
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'
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)
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.
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)
Thank you!!
Hello, The error itself explain what's the problem.In ...READ MORE
950down voteaccepted It's because any iterable can be ...READ MORE
This is because join is a "string" ...READ MORE
The likeliest answer is that it just ...READ MORE
You can also use the random library's ...READ MORE
Syntax : list. count(value) Code: colors = ['red', 'green', ...READ MORE
Enumerate() method adds a counter to an ...READ MORE
You can simply the built-in function in ...READ MORE
Hi@MUHAMMAD, I tried to run the exact code ...READ MORE
Hi, If you successfully installed opencv in your ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.