Question: Write a python program ( using the starter file provided below ) that appends ( a mode ) data to an existing file ( players

Write a python program (using the starter file provided below) that appends (a mode) data to an existing file (players.txt). Your program must:
open the file (players.txt)
ask for information about your three additional players (real or fictional)
store the information in the file
close the file
reopen the file for reading (r mode)
read and print out each line
# Baseball players starter file players.py
def main():
# Open an output file, players.txt(in append mode 'a')
# Enter the player's number, name, and home runs for three additional players
# Store each player's data in the output file
outfile.write(f"{number: 2d}{name}{hrs: 2d}
")
# Close the output file
outfile.close()
# Reopen the file for input (printing)
# Print out the data for each player
# Close the input file
main()
#players.txt file to modify
17 Shohei Otani 45
99 Aaron Judge 62
3 Babe Ruth 60
9 Ted Williams 40
2 Derek Jeter 23

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!