Guest User

Untitled

a guest
Feb 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. #PROJECT 2
  2. #LAU CHIU YIN
  3. #Topic: Which 2 teams have the highest and which team has the lowest shooting percentage in the NBA in season 2013-14? Do the shooting percentage affect teams win? The average wins and shooting percentage of 30 teams
  4. import csv
  5. def mostWinning():# the function to find the most and the second most winnings teams
  6. file = open("NBAstat.csv")
  7. reader = csv.reader(file)
  8. biggest=0
  9. name=0
  10. name2=0
  11. biggest2=0
  12. for i in reader:
  13. if eval(i[1]) > biggest:
  14. name2=name #to make name2 always behine name
  15. name = i[0]
  16. biggest2=biggest #to make biggest2 always smaller than biggest
  17. biggest = eval(i[1])
  18. print("The most winning team is",name,biggest,"wins")
  19. print("the second most winng team is",name2,biggest2,"wins")
  20. print()
  21.  
  22. def lestWinning(): # function to find the least and the second least winnings team
  23. file = open("NBAstat.csv")
  24. reader = csv.reader(file)
  25. lowest=100
  26. lowest2=100
  27. for j in reader:
  28. if eval(j[1])<lowest2 and lowest2>lowest:
  29. name2=j[0]
  30. lowest2=eval(j[1])
  31. if eval(j[1])<lowest:
  32. name= j[0]
  33. lowest=eval(j[1])
  34.  
  35. print("The least winnings team is",name,lowest,"wins")
  36. print("The seconnd least winnings team is ",name2,lowest2,"wins")
  37. print()
  38.  
  39. def highPer(): # function to find the highest shooting percentage
  40. file = open("NBAstat.csv")
  41. reader = csv.reader(file)
  42. highest=0
  43. highest2=0
  44. name=0
  45. name2=0
  46. for i in reader:
  47. if eval(i[2])>highest:
  48. name2=name
  49. name=i[0]
  50. highest2=highest
  51. highest=eval(i[2])
  52. print("The highest shooting percentage team is",name,str(highest)+"%")
  53. print("The second highest shooting percentage team is", name2, str(highest2) + "%")
  54. print()
  55.  
  56. def lowPer():# function to find the lowest shooting percentage
  57. file = open("NBAstat.csv")
  58. reader = csv.reader(file)
  59. lowest=100
  60. lowest2=100
  61. for i in reader:
  62. if eval(i[2])<lowest2 and lowest2>lowest:
  63. name2=i[0]
  64. lowest2=eval(i[2])
  65. if eval(i[2])<lowest:
  66. name=i[0]
  67. lowest=eval(i[2])
  68. print("The lowest shooting percentage team is ",name,str(lowest)+"%")
  69. print("The second lowest shooting percentage team is ", name2, str(lowest2) + "%")
  70. print()
  71.  
  72. def av_wins(): # function to find the average wins of 30 teams
  73. file = open("NBAstat.csv")
  74. reader = csv.reader(file)
  75. list=[]
  76. for i in reader:
  77. list.append(i)
  78. tot = 0
  79. j = 0
  80. while j<len(list):
  81. tot+=eval(list[j][1])
  82. j+=1
  83. return tot/j
  84. def av_FG(): # function to find the average shooting percentage of 30 teams
  85. file = open("NBAstat.csv")
  86. reader = csv.reader(file)
  87. list = []
  88. for i in reader:
  89. list.append(i)
  90. tot = 0
  91. h = 0
  92. while h < len(list):
  93. tot += eval(list[h][2])
  94. h += 1
  95. return tot / h
  96.  
  97.  
  98. def main(): # the main function of all function
  99. mostWinning()
  100. lestWinning()
  101. highPer()
  102. lowPer()
  103. main()
  104. print("the average wins of 30 teams are",av_wins())
  105. print("the average shooting percentage of 30 teams is",int(av_FG()),"%")
Add Comment
Please, Sign In to add comment