I keep getting the error list index out of range. I'm not sure what I'm doing wrong.
My code:
from scanner import *
def small(array):
smallest=array[0]
for i in range(len(array)):
if (array[i]<smallest):
smallest=array[i]
return smallest
def main():
s=Scanner("data.txt")
array=[]
i=s.readint()
while i!="":
array.append(i)
i=s.readint()
s.close()
print("The smallest is", small(array))
main()
The traceback I get:
Traceback (most recent call last):
File "file.py", line 21, in <module>
main()
File "file.py", line 20, in main
print("The smallest is", small(array))
File "file.py", line 5, in small
smallest=array[0]
IndexError: list index out of range
small()function.. consider adding error handling for that!