Answered step by step
Verified Expert Solution
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 on July for soccer clubs: StLouisCity.txt PortlandTimbers.txt and VancouverWhitecaps.txt Here is what each field in the file means:
: First Name initial
: Last Name
: Position initial
: Number of Games Played
: Number of Games Started
: Number of Goals
: Number of Assists
: Number of Shots
: Number of Shots on Target
: Passing Accuracy
: Number of Tackles
: Number of Interceptions
: Number of Fouls Committed
: Number of Fouls Drawn
: Number of Yellow Cards
: 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 eg 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 goaltoshot 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 goaltoshot 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: VancouverWhitecapstxt
Processing VancouverWhitecapstxt
Number of players processed:
Total number of cards issued to the team:
Player with the best goaltoshot ratio: S Becher
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started