Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using PYTHON: In this week's assignment, you will create a computer program to process and analyze soccer statistics. This assignment will demonstrate the ability to

Using PYTHON:
In this week's assignment, you will create a computer program to process and analyze soccer statistics. This assignment will demonstrate the ability to create and handle data structures. Refer to the lecture videos for guidance on using lists.
Here are statistics for 3 soccer clubs: (Please see later posts for statistics) Here is what each field in the file means:
0: First Name (initial)
1: Last Name
2: Position (initial)
3: Number of Games Played
4: Number of Games Started
5: Number of Goals
6: Number of Assists
7: Number of Shots
8: Number of Shots on Target
9: Passing Accuracy
10: Number of Tackles
11: Number of Interceptions
12: Number of Fouls Committed
13: Number of Fouls Drawn
14: Number of Yellow Cards
15: Number of Red Cards
Programming Specifications
Create a global variable called listOfStats. Initialize it to be an empty list.
Define a function called ProcessStatsFile. First, ask the user for the path to a file. After opening the provided file, read each line in the file. Split each line, and append this list to listOfStats. Finally, print out the number of players that have been processed (e.g. number of lines in the file).
Define a function called CalculateCardTotal. This function adds up all the yellow and red cards given to all the players on the roster. Create a total variable and initialize it to zero, loop through each player stat in listOfStats, and add the number of yellow cards and number of red cards to the total. Finally, print out the number of cards issued to the team.
Define a function called FindBestGoalToShotRatio. This function will find the player on the roster that has the best goal to shot ratio. The ratio is simply the number of goals divided by the number of shots. Loop through each player stat in listOfStats. Compute the goal-to-shot ratio for the player. You will need to write a conditional to determine if this player has the best ratio. If this player has the best ratio, save the player's first name, last name, and the ratio. Once you determine who has the best ratio, print out the player's name and their goal-to-shot ratio (as a percentage).
In the main portion of the script, call ProcessStatsFile, then call CalculateCardTotal, and then call FindBestGoalToShotRatio.
Save your program as a Python file named soccerStats.py.
Here is a test run. The program output is indicated in blue; my response is in black.
Provide path to input file: ./VancouverWhitecaps.txt
Processing ./VancouverWhitecaps.txt
Number of players processed: 26
Total number of cards issued to the team: 48
Player with the best goal-to-shot ratio: S. Becher (30.8%)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions