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...
In python, write a program that asked the user to enter the monthly costs for the...
In python, write a program that asked the user to enter the monthly costs for the following expenses incurred from operating his automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should display total monthly cost and annual cost. Also, should contain main and calcExpenses functions, calcExpenses should only calculate the expenses and everything else should happen in the main function.
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 Language: Similar to Project 3, write a program that loops a number from 1 to...
Python Language: Similar to Project 3, write a program that loops a number from 1 to 10 thousand and keeps updating a count variable according to these rules: if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if none of the above conditions match for the number, increase count by the number. Before the loop begins,...
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): odd...
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): odd Binary numbers // 00000000, 0101, 111111, etc. Show: Finite Automaton Definition, Graph, Table
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): unsigned...
Write a program in python programming language to implement/simulate a finite automaton that accepts (only): unsigned integer numbers // 123, 007, 4567890, etc. Show: Finite Automaton Definition, Graph, Table.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT