USING PYTHON IDLE 3.6.1 Who was the best NBA basketball player? The NBA is North
ID: 3811813 • Letter: U
Question
USING PYTHON IDLE 3.6.1
Who was the best NBA basketball player? The NBA is North America's professional men's basketball league. You are going to write a program to find the best players in NBA history. Using the csv file provided with the lab. Calculate the efficiency for each player, using the csv file provided with the lab. NBA player's performance is evaluated using the following efficiency formula Efficiency ((pts reb asts stl blk) ((fga -fgm (fta -ftm +turnover gp 1. Find the top 50 players with the best efficiency results and Display those 50 from best to worst. 2. Find and displaythe Player who played the most minutes 3. Find and display the player who play the most games 4. Find and display the Player who scored the most points 5. Find and display the Player who got the most penalties 6. Find and display the Player who made the most free throws. Remember: All indexes start on ZERO. The First line in the file provides the labels of the columns.Explanation / Answer
import csv
import operator
eff ={}
m=0 #minutes
mg=0 #most games
mp=0 #most points
with open('file.csv','rb') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
Efficiency = ((int(row['pts'])+int(row['reb'])+int(row['asts'])+int(row['stl'])+int(row['blk']))-((int(row['fga'])-int(row['fgm']))+(int(row['fta'])-int(row['ftm']))+int(row['turnover'])))/int(row['gp'])
eff[row['ilkid']]=Efficiency #Here adding values to the dictionary
if (m <= int(row['minutes'])):
m=int(row['minutes'])
bestminutes = row['ilkid']
if (mg <= int(row['gp'])):
mg = int(row['gp'])
mostgames = row['ilkid']
if (mp <= int(row['pts'])):
mp = int(row['pts'])
mostpoints = row['ilkid']
effiency_list = sorted(eff.items(), key=operator.itemgetter(1),reverse=True)
print effiency_list," most minutes: ",bestminutes," mostgames: ",mostgames," mostpoints: ",mostpoints
Output:
>>>
[('AUBUCCH01', 0), ('ABRAMJO01', -3)]
most minutes: AUBUCCH01
mostgames: ABRAMJO01
mostpoints: ABRAMJO01
>>>
Note: You provided .csv file as a image that's why i typed only two players data.
I didn't understand penalities and freethrows values contained columns. But please follow the process what i am using for find out most minutes , most games and most points.
At file path, please provide your filepath in the programme. i didn't provide my ".csv" file. I taught that you have complet .csv file.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.