Every time I try to run my code and open a specific text document which is fairly long, it says string index out of range. I was wondering if any of you could help me solve this problem. I have to get my code to spit out more than what I have it doing right now, but this is a start and I didn't figure it wise to carry on without fixing the initial error.
file = open(input("Enter File Name:"))
lines = file.readlines()
file.close()
number_chars = 0
number_words = 0
largest_word = ""
smallest_word = ""
count_words = 0
largest = int(0)
smallest = int(999999)
average = 0
count = 0
sum = 0
for item in lines:
is_word = False
item = item.strip()
char = item[0]
count_words = count_words + 1
if char >= 'a' and char <= 'z':
is_word = True
elif char >= 'A' and char <= 'Z':
is_word = True
if is_word == True:
if(len(largest_word) < len(item)):
largest_word = item
if(len(smallest_word) > len(item)):
smallest_word = item
number_chars += len(item)
else:
item = int(item)
count = count + 1
sum = sum + item
if(count == 1 or item > largest):
largest = item
if(count == 1 or item < smallest):
smallest = item
print("Reading", "name_list.txt")
print("found",count,"numbers")
print("largest number :", largest)
print("smallest numer :", smallest)
Average = sum // count
print("Average :", Average)
print(largest_word)
print(smallest_word)