Question

The the results or the golf tournament played at the end of March. The Club president Mr. Martin has asked you to write two p
Henry Zebulon 8.3 83 4.2 72 lan Fleming 7.7 84 Jan Holden 7.9 79 Kit Possum 10.3 93 Landy Bern Mona Docker 11.3 98 7.1 80 Kev
Python I already saved the data into a file (First name, Last name, Handicap, Score) I just need to know how to re-open the f
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program code to copy:-

#Open the file for reading
fin = open("golf.txt", "r")

#printing Heading
print("First-Name\tLast-Name\tHandicap\tScore\tResult")

#Loop read the content of input file line by line and
#store each line into variable 'line' till end of input file
for line in fin:
#split the line read from the file
playerInfo = line.split()

#get the first name
fname = playerInfo[0]
#get the last name
lname = playerInfo[1]
#get the Handicap
handicap = playerInfo[2]
#get the score converted into int
score = int(playerInfo[3])

#Checking for the result
if score == 80:
result = 'Made Par'
elif score < 80:
result = 'Under Par'
else:
result = 'Over Par'

#Displaying the player information
print(fname+"\t\t"+lname+"\t\t"+handicap+"\t\t"+str(score)+"\t"+result)
  
#Closing both input file
fin.close()

Screenshot of Program Code:-

#Open the file for reading fin = open(golf.txt, r) #printing Heading print (First-Name\tLast-Name\tHandicap\tScore\tResu

Screenshot of output:-

Handicap Score 11.2 First-Name Andrew Betty Connie Donny Ernie Fred 12.8 14.6 0 Greg Henry Ian Jan Kit Landy mona Kevin Pam R

You need to create 'golf.txt" file before executing the above program code and store it into current working folder.

Content of "golf.txt" :-

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

Add a comment
Know the answer?
Add Answer to:
The the results or the golf tournament played at the end of March. The Club president...
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
  • The Springfork Amateur Golf Club has a tournament every weekend. The club president has asked you...

    The Springfork Amateur Golf Club has a tournament every weekend. The club president has asked you to write a program that will read each player's name and score as keyboard input, and then save these as records in a file named golf.txt. First, have the program ask the user how many players they want to add to their record. Then, ask the user for each name and score individually. golf.txt should be structured so that there is a line with...

  • CHAPTER 6 Question 10 (Programming Exercises) The Springfork Amateur Golf Club has a tournament every weekend....

    CHAPTER 6 Question 10 (Programming Exercises) 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, then save these as records in a file name 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...

  • Write the C program, to achieve as shown in the sample code execution, using the given...

    Write the C program, to achieve as shown in the sample code execution, using the given struct and using the comments in the given main program below: typedef struct{ char first[20]; char last[20]; float gpa; int score; } student; int main(void){ student *ptr; //first name //last name //student gpa //student score } //ask a user to enter the number of students, num //dynamically allocate memory for an array of students of the appropriate size (i.e. //num that the user just...

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