375,933 views
36 votes
36 votes
The Marietta Country Club has asked you to write a program to gather, then display the results of the golf tournament played at the end of March. The Club president Mr. Martin has asked you to write two programs.

The first program will input each player's first name, last name, handicap and golf score and then save these records in a file named golf.txt (each record will have a field for the first name, last name, handicap and golf score).
The second program will read the records from the golf.txt file and display them with appropriate headings above the data being displayed.
If the score is = Par, then display 'Made Par'
If the score is < Par, then display 'Under Par'
If the score is > Par, then display 'Over Par'
There are 16 players in the tournament. Par for the course is 80. The data is as follows:
Andrew Marks 11.2 72
Betty Franks 12.8 89
Connie William 14.6 92
Donny Ventura 9.9 78
Ernie Turner 10.1 81
Fred Smythe 8.1 75
Greg Tucker 7.2 72
Henry Zebulon 8.3 83
Ian Fleming 4.2 72
Jan Holden 7.7 84
Kit Possum 7.9 79
Landy Bern 10.3 93
Mona Docker 11.3 98
Kevin Niles 7.1 80
Pam Stiles 10.9 87
Russ Hunt 5.6 73

User Jningthou
by
3.0k points

1 Answer

19 votes
19 votes

Answer:

Step-by-step explanation:

The following program is written in Python. It creates two functions, one for writting the players and their scores to the file, and another function for reading the file and outputting whether or not they made Par. The functions can be called as many times that you want and the writeFile function allows for 16 inputs to be made when called. A test case has been provided with all of the players mentioned in the question. The output can be seen in the attached image below.

def writeFile():

file = open('output.txt', 'w')

for x in range(16):

firstName = input("Enter First Name:")

lastName = input("Enter Last Name:")

handicap = input("Handicap:")

score = input("Score:")

file.write(str(firstName) + " " + str(lastName) + " " + str(handicap) + " " + str(score) + "\\")

file.close()

def readFile():

file = open('output.txt', 'r')

for line in file:

lineArray = line.split(" ")

if int(lineArray[-1]) < 80:

print(str(lineArray[0]) + " " + str(lineArray[1]) + " Under Par" )

elif int(lineArray[-1]) == 80:

print(str(lineArray[0]) + " " + str(lineArray[1]) + " Made Par")

else:

print(str(lineArray[0]) + " " + str(lineArray[1]) + " Over Par")

file.close()

writeFile()

readFile()

The Marietta Country Club has asked you to write a program to gather, then display-example-1
User Louise McMahon
by
3.0k points