score_board = []
for i in range(0, int(input())):
score_board.append(int(input()))
new_board = sorted(list(set(score_board)), reverse=True)
print(new_board[1])
Getting Runtime Error. Can someone suggest mean what mistake I'm doing in my code. I'm trying to upload code in hackerrank but i suggest below mentioned error. My code problem work on my laptop. I cant grasp the problem help me.Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given scores. Store them in a list and find the score of the runner-up.Print the runner-up score.
traceback:
Error (stderr)
Traceback (most recent call last):
File "Solution.py", line 3, in <module>
score_board.append(int(input()))
ValueError: invalid literal for int() with base 10: '2 3 6 6 5'
input (stdin)
`5`
`2 3 6 6 5`
You are passing multiple items to append
which only accept a single item. If you want to add more than one item to your list at the same time, try using extend
:
score_board = []
for i in range(int(input())):
score_board.extend([int(x) for x in input().split()])
new_board = sorted(list(set(score_board)), reverse=True)
print(new_board[1])
This would work with your current input style. You also don't need to specify the 0
in the for loop, since it automatically starts at 0.