Question

by python Your program should open the file and generate three separate lists from the data,...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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:

Add a comment
Know the answer?
Add Answer to:
by python Your program should open the file and generate three separate lists from the data,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT