by python
Your program should open the file and generate three separate lists from the data, one for their full names (First Name and Last Name as single string), one for the positions, and one for batting averages. Your program should then output the following:
David Freitas, catcher, is batting 0.197.
Chris Hermann, catcher, is batting 0.242.
Mike Zunino, catcher, is batting 0.189.
Robinson Cano, infielder, is batting 0.287
.
.
.
Denard Span, outfielder, is batting 0.310.
Nelson Cruz, designated hitter, is batting 0.267.
.TXT FILE:
Last First Position Batting
Average
Freitas David Catcher
0.197
Hermann Chris Catcher
0.242
Zunino Mike Catcher 0.189
Cano Robinson Infielder
0.287
Gordon Dee Infielder
0.283
Healy Ryon Infielder
0.240
Romine Andrew Infielder
0.203
Seager Kyle Infielder
0.233
Segura Jean Infielder
0.323
Gamel Ben Outfielder
0.286
Haniger Mitch Outfielder
0.272
Heredia Guillermo Outfielder
0.231
Span Denard Outfielder
0.310
Cruz Nelson DH 0.267
code:
import csv
with open ('players.txt', 'r') as f:
fullname = []
postion = []
battingAverage= []
for row in csv.reader(f,delimiter='\t'):
fullname.append(row[1]+' '+row[0])
postion.append(row[2])
battingAverage.append(row[3])
for i in range(1,len(fullname)):
print(fullname[i]+',', postion[i], "is batting
"+battingAverage[i])
output screenshot:
by python Your program should open the file and generate three separate lists from the data,...