'ValueError: invalid literal for int() with base 10. How to prevent this? [duplicate]
I am trying to get the second-highest number from the list which takes in user input but I keep getting this- ValueError: invalid literal for int() with base 10: I tried a sample case where n = 5 and I entered the list as [2,3,6,6,5] and I'm getting the same error
How do I go about it, the code is given below:
list1 = []
n = int(input())
for i in range(0,n+1):
ele = int(input()) //error coming in this line
list1.append(ele)
new_list = set(list1)
new_list.remove(max(new_list))
print(max(new_list))
this is the traceback
Traceback (most recent call last):
File "/tmp/submission/20220221/18/09/hackerrank-1dcd86ec44b50895801520a4a2d0e542/code/Solution.py", line 4, in <module>
ele = int(input())
ValueError: invalid literal for int() with base 10: '2 3 6 6 5'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
