In: Computer Science
Using python:
The Springhill Amateur Golf Club has a tournament every weekend. The club president has asked you to write a Menu-Driven program which has the following functionality:
2. Reads each player's name and golf score from the text file golf.txt and provides an average score.
The python file for the above functionality is given below. File name: players.py
file = open('golf.txt').read().split('\n')
no_of_players = len(file)
sum = 0
for scores in file:
name_numbers = (scores.split(' '))
sum += int(name_numbers[1])
average = sum/no_of_players
print('>>>>>>>>>>>>>>> MENU <<<<<<<<<<<<<<<')
print('1. Display Number of Players')
print('2. Display name of players with scores.')
print('3. Display average of scores.' )
choice = input('Enter your Choice. ')
if choice == 1:
print('There are {} players listed in the file.'.format(no_of_players))
elif choice == 2:
for scores in file:
name_numbers = (scores.split(' '))
print('{} has a score of {}'.format(name_numbers[0], name_numbers[1]))
elif choice == 3:
print('The average score is {}'.format(average))
else:
pass
The text file used is attached below. File Name: golf.txt
Nicolus_Amber 20
Tico_Salamanca 59
Maroon_Blade 46
Joshua_Orgon 30
Margon_Thaty 43
Mico_Stuart 24