Assuming your .txt file includes the "Movies: Drama" line, as you listed, it's because the first line of the text file has no comma in it. Therefore splitting that first line on a comma only results in 1 element (element 0), NOT 2, and therefore there is no values[1] for the first line.
It's not unusual for data files to have a header line that doesn't contain actual data. Import modules like Pandas will typically handle this automatically, but open() and readlines() don't differentiate.
The easiest thing to do is just slice your list variable (lines) so you don't include the first line in your loop:
fp = open("Movies.txt", "r")
lines = fp.readlines()
for line in lines[1:]:
values = line.split(", ")
year = int(values[1])
if year < 1990:
print(values[0])
Note the "lines[1:]" modification. This way you only loop starting from the second line (the first line is lines[0]) and go to the end.
Movies: DramaThere is no,in this. So when you split atlines.split(', ')the resulting list is just one entry that says:['Movies: Drama']. Sovalues[1]` will be list index out of range.split()returned a list with only one element, therevalues[1]does not exist when processing that line. One solution would be to doheader = fp.readline()just after opening the file, so that the mainforloop never sees that line.values[1]failed), and why ([1]is the index; it is "out of range"; therefore,valuesdoesn't have enough elements in it for there to be a[1]to access). From there, you work backwards (valueswas determined byline.split(", ")- so, what did that do?)