I am attempting to make a program in Python 3.7 where you would input integers one after another until you terminate it by entering the value -3. Once you input -3, the program would print the second highest number you've listed.
My current code is:
My current code is:
a=[] n=int(input("Enter number:")) for i in range(1,n+1): n=int(input("Enter number:")) a.append(n) if n == -3: break a.sort() print("Second largest number is:",a[n-2])I keep getting the error:
Error:Traceback (most recent call last):
File "main.py", line 9, in <module>
print("Second largest number is:",a[n-2])
IndexError: list index out of range
If anyone could help me out it would be greatly appreciated as I am still a beginner with this language.