My goal is to read in a file, and return the corresponding information that the user has asked for. For example my text file looks like this (it represents the year and the students heights from that year):
2013
5.5 6.3 4.0 5.2 5.1
2014
4.6 4.8 5.3 5.6 6.0
2015
3.8 4.9 6.0 5.8 5.7
Basically if I enter 2013, I want it to return the list of heights that correspond to that year (the line below). But I can't event get it to print back the list of strings. Some help would be great.
#read in text file
f = open("students.txt")
#ask for student year
year = input("Enter the year for the data you want to receive:")
#check to see if year is avialble
line = f.readline()
while True:
line = f.readline().split()
if line:
if line == year:
print(line)
else:
break
print("No data")