Question

In: Computer Science

Python Language: The Marietta Country Club has asked you to write a program to gather, then...

Python Language:

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. 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 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'.

REMEMBER to put your name on the lab with comments, and comment throughout the program with what the program is doing.

Solutions

Expert Solution

CODE:

#program 1
#writing to file golf.txt
scores = []
details = {'firstName':'','lastName':'','handicap':0,'score':0}
for i in range(16):
#asking the user to enter the details
print('Enter the details of player: ')
details['firstName'] = input('Enter the first name: ')
details['lastName'] = input('Enter the last name: ')
details['handicap'] = float(input('Enter the handicap: '))
details['score'] = float(input('Enter the score: '))
scores.append(details)
details = {'firstName':'','lastName':'','handicap':0,'score':0}
  
#opening the file
file = open('golf.txt','w')
for i in scores:
#writing each line
file.write('{} {} {} {}\n'.format(i['firstName'],i['lastName'],str(i['handicap']),str(i['score'])))
  
file.close()
print('Files Written!')

#second program
file_in = open('golf.txt','r')
#reads the line from the file
lines = [x.split('\n')[0] for x in file_in.readlines()]
for i in lines:
par = ''
#checking the score of each entry
score = float(i.split(' ')[3])
if(score == 80):
par = 'Made Par'
elif(score < 80):
par = 'Under Par'
elif(score > 80):
par = 'Over Par'
#priting with the heading
print('{}\t{}'.format(i,par))
file_in.close()

____________________________________________________

CODE IMAGES AND OUTPUT:

________________________________________________

golf.txt

Andrew Marks 11.2 72.0
Betty Franks 12.8 89.0
Connie William 14.6 92.0
Donny Ventura 9.9 78.0
Ernie Turner 10.1 81.0
Fred Smythe 8.1 75.0
Greg Tucker 7.2 72.0
Henry Zebulon 8.3 83.0
Ian Fleming 4.2 72.0
Jan Holden 7.7 84.0
Kit Possum 7.9 79.0
Landy Bern 10.3 93.0
Mona Docker 11.3 98.0
Kevin Niles 7.1 80.0
Pam Stiles 10.9 87.0
Russ Hunt 5.6 73.0
_____________________________________________

Feel free to ask any questions in the comments section
Thank You!


Related Solutions

For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
In this question, you are asked to write a simple java program to understand natural language....
In this question, you are asked to write a simple java program to understand natural language. The user will enter the input following the format: Name came to City, Country in Year. For example: Robin came to Montreal, Canada in 2009. Assume a perfect user will follow the exactly above formats for the inputs. Your program should be able to analyze the key words (Name, City, Country and Year) from the inputs and reorganize the outputs following format: Name stay...
Write the program in C++ The Rebel food truck has asked you to write a program...
Write the program in C++ The Rebel food truck has asked you to write a program for them to do both inventory and sales for their food wagon. Ben and Dave run the food truck and they already have full time day jobs so they could really use your help. The food truck sells: hamburger, hotdogs, chilli, fries and soda. The truck has spots for 200 hamburger patties, 200 hot dogs, 75 hamburger buns, 75 hot dog buns, 500 ounces...
Write a program in python language, which accepts 2 numbers and a + sign (for addition)...
Write a program in python language, which accepts 2 numbers and a + sign (for addition) A sign - (for subtraction) A sign * (for multiplication), / (for division) Then calculate and to display the result of the operation he chose with the two numbers. Displaying the appropriate message
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
Language Python with functions and one main function Write a program that converts a color image...
Language Python with functions and one main function Write a program that converts a color image to grayscale. The user supplies the name of a file containing a GIF or PPM image, and the program loads the image and displays the file. At the click of the mouse, the program converts the image to grayscale. The user is then prompted for a file name to store the grayscale image in.
Python This week you will write a program in Python that mimics an online shopping cart...
Python This week you will write a program in Python that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers...
PYTHON PYTHON Recursive Functions. In this problem, you are asked to write three recursive functions. Implement...
PYTHON PYTHON Recursive Functions. In this problem, you are asked to write three recursive functions. Implement all functions in a module called problem1.py. (10 points) Write a recursive function called remove char with two parameters: a string astr and a character ch. The function returns a string in which all occurrences of ch in astr are removed. For example, remove char("object oriented", ’e’) returns the string "objct orintd". Your implementation should not contain any loops and may use only the...
Programming language is in python 3 For this project, you will import the json module. Write...
Programming language is in python 3 For this project, you will import the json module. Write a class named NobelData that reads a JSON file containing data on Nobel Prizes and allows the user to search that data. It just needs to read a local JSON file - it doesn't need to access the internet. Specifically, your class should have an init method that reads the file, and it should have a method named search_nobel that takes as parameters a...
Programming language is python 3 For this project, you will import the json module. Write a...
Programming language is python 3 For this project, you will import the json module. Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet, saving data to a JSON file, loading data from a JSON file, and getting a set of all pet species. It will only be loading JSON files that it has previously created, so the internal organization of the data is up to you. The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT