Using the script below and the attached file (mlb-teams.txt) as a starting point complete the following two tasks (each task worth 10 points): Objective 1. Comment headers 2. Covert the open()...

1 answer below »

Using the script below and the attached file (mlb-teams.txt) as a starting point complete the following two tasks (each task worth 10 points):








































Objective
1. Comment headers
2. Covert theopen()function to withopen()


3. Replace thew+with the correct option for appending to the file

4. Usingf.write(), add the three teams specified to mlb-teams.txt

5. Using thef.write()function, add the player stored in the variable tohall_of_fame.txt


6. Replace therwith the correct option for appending to the file

7. Using thef.write()function, add the 3 players specified tohall_of_fame.txt


8. Import the data fromhall_of_fame.txtinto a variable calledhof_players


9. Using the list index, print the MLB team closest to your hometown to the screen

10. Using the list index, print one of the players in thehof_playersvariable



03_Activity/hall_of_fame.txt Bobby Bonds Al Kaline Mickey Mantle Willie Mays Babe Ruth Lou Gehrig Roy Campanella Jackie Robinson __MACOSX/03_Activity/._hall_of_fame.txt 03_Activity/mlb-teams.txt Arizona Diamondbacks Atlanta Braves Baltimore Orioles Boston Red Sox Chicago Cubs Chicago White Sox Cincinnati Reds Cleveland Indians Colorado Rockies Detroit Tigers Houston Astros Kansas City Royals Los Angeles Angels Los Angeles Dodgers Miami Marlins Milwaukee Brewers Minnesota Twins New York Mets New York Yankees Oakland Athletics Philadelphia Phillies Pittsburgh Pirates San Diego Padres San Fransisco Giants Seattle Mariners St Louis Cardinals Tampa Bay Rays Texas Rangers Toronto Blue Jays Washington Nationals __MACOSX/03_Activity/._mlb-teams.txt 03_Activity/mlb-players.txt Randy Johnson Hank Aaron Cal Ripken Ted Williams Ernie Banks Frank Thomas Johnny Bench Bob Feller Larry Walker Hank Greenberg Nolan Ryan George Brett Mike Trout Jackie Robinson Gary Sheffield Robin Yount Kirby Puckett Tom Seaver Babe Ruth Catfish Hunder John Kruk Roberto Clemente Tony Gwynn Willie Mays Ken Griffey Jr. Stan Musial Evan Longoria Ivan Rodriguez Joe Carter Max Scherzer __MACOSX/03_Activity/._mlb-players.txt 03_Activity/mlb_updates.py # 1. COMPLETE HEADER COMMENTS # # # Input / Output # w write permissions # w+ write permissions w\create blank doc # r read only permission # a append ####################### # MLB TEAMS ####################### # 2. The example below uses the old method of opening an external file. # Convert the open() function below [line 19 - 22 ]to with open(). # Baseball Team Text file import f = open('mlb-teams.txt', 'r') mlb = f.read().splitlines() f.close() # 3. Replace the w+ with the appropriate option for appending the file. with open('mlb-teams.txt', 'w+') as f: # 4. Using the f.write() function, add three more teams to the list: # [ Seattle Pilots, Washington Senators & Montreal Expos ] ####################### # HALL OF FAME PLAYERS ####################### favorite_baseball_player = "Old Hoss Radbourne" with open("hall_of_fame.txt", 'w+') as f: f.write("Bobby Bonds\n") f.write("Al Kaline\n") f.write("Mickey Mantle\n") f.write("Willie Mays\n") # 5. Using the f.write() funtion, add the player stored in # favorite_baseball_player to the hall_of_fame.txt file # Note: You MUST reference the variable in this part. f.write('\n') # 6. Replace the r with the appropriate option for appending the file. with open('hall_of_fame.txt', 'r') as f: # 7. Using the f.write() function, add 3 more players the list: # [Babe Ruth, Willie Stargell & Roberto Clemente] # 8. Using with open(), place the values stored in hall_of_fame.txt into a variable called hof_players # 9. Write a print statement below with the MLB Team closest to your Home Town. print (mlb[18]) # 10. Write a print statement to print one of the players stored in the variable hof_players created in step 8. __MACOSX/03_Activity/._mlb_updates.py __MACOSX/._03_Activity
Answered 2 days AfterOct 11, 2021

Answer To: Using the script below and the attached file (mlb-teams.txt) as a starting point complete the...

Ketaki answered on Oct 13 2021
147 Votes
# 1. COMPLETE HEADER COMMENTS
#
#
# Input / Output
# w write permissions
# w+ write permissions
w\create blank doc
# r read only permission
# a append
#######################
# MLB TEAMS
#######################
# 2. The example below uses the old method of opening an external file.
# Convert the open() function below [line 19 - 22 ]to with open().
# Baseball Team Text file import
with open('mlb-teams.txt', 'r') as f:
    mlb = f.read().splitlines()
f.close()
# 3. Replace the w+ with the appropriate option for appending the file.
with open('mlb-teams.txt', 'a') as f:

    # 4. Using the f.write() function, add...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here