Ask Question
25 July, 14:09

The Springfork Amateur Golf Club has a tournament every weekend. The club president

has asked you to write two programs:

1. A program that will read each player's name and golf score as keyboard input, and then

save these as records in a file named golf. txt. (Each record will have a field for the

player's name and a field for the player's score.)

2. A program that reads the records from the golf. txt file and displays them.

+2
Answers (1)
  1. 25 July, 15:21
    0
    The Python code is given below for each question.

    Explanation:

    1:

    if __name__ = = '__main__':

    f = open ('golf. txt', 'w')

    n = int (input ("Enter number of players:"))

    for i in range (n):

    name = input ("Enter name of player number " + str (i + 1) + ":")

    score = int (input ("Enter score of player number " + str (i + 1) + ":"))

    f. write (name + "/n" + str (score) + "/n")

    f. close ()

    2:

    try:

    with open ('golf. txt') as r:

    lines = r. readlines ()

    for i in range (0, len (lines), 2):

    print ("Name:", lines[i]. strip ())

    print ("Score:", lines[i+1]. strip ())

    print ()

    except FileNotFoundError:

    print ("golf. txt is not found!")
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “The Springfork Amateur Golf Club has a tournament every weekend. The club president has asked you to write two programs: 1. A program that ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers