As you can see from the code below, I have my program read text from a text file (homework.txt) to a list called heightandweight. I then have it print 3 items in the list at a time. However it doesn't print the 3 pieces of information on one line. How would I do that?
myFile = open("homework.txt","rt")
heightandweight = []
for line in myFile:
line = line.strip("\n")
heightandweight.append(line)
print(heightandweight)
myFile.close()
for e in range (0, len(heightandweight),3):
for i in heightandweight[e:e+3]:
print (i)
The above code will output:
['James', '73', '1.82', 'Peter', '78', '1.80', 'Jay', 'Beth', '65', '1.53', 'Mags', '66', '1.50', 'Joy', '62', '1.34']
James
73
1.82
Peter
78
1.80
Jay
Beth
65
1.53
Mags
66
1.50
Joy
62
1.34