Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #PROJECT 2
- #LAU CHIU YIN
- #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
- import csv
- def mostWinning():# the function to find the most and the second most winnings teams
- file = open("NBAstat.csv")
- reader = csv.reader(file)
- biggest=0
- name=0
- name2=0
- biggest2=0
- for i in reader:
- if eval(i[1]) > biggest:
- name2=name #to make name2 always behine name
- name = i[0]
- biggest2=biggest #to make biggest2 always smaller than biggest
- biggest = eval(i[1])
- print("The most winning team is",name,biggest,"wins")
- print("the second most winng team is",name2,biggest2,"wins")
- print()
- def lestWinning(): # function to find the least and the second least winnings team
- file = open("NBAstat.csv")
- reader = csv.reader(file)
- lowest=100
- lowest2=100
- for j in reader:
- if eval(j[1])<lowest2 and lowest2>lowest:
- name2=j[0]
- lowest2=eval(j[1])
- if eval(j[1])<lowest:
- name= j[0]
- lowest=eval(j[1])
- print("The least winnings team is",name,lowest,"wins")
- print("The seconnd least winnings team is ",name2,lowest2,"wins")
- print()
- def highPer(): # function to find the highest shooting percentage
- file = open("NBAstat.csv")
- reader = csv.reader(file)
- highest=0
- highest2=0
- name=0
- name2=0
- for i in reader:
- if eval(i[2])>highest:
- name2=name
- name=i[0]
- highest2=highest
- highest=eval(i[2])
- print("The highest shooting percentage team is",name,str(highest)+"%")
- print("The second highest shooting percentage team is", name2, str(highest2) + "%")
- print()
- def lowPer():# function to find the lowest shooting percentage
- file = open("NBAstat.csv")
- reader = csv.reader(file)
- lowest=100
- lowest2=100
- for i in reader:
- if eval(i[2])<lowest2 and lowest2>lowest:
- name2=i[0]
- lowest2=eval(i[2])
- if eval(i[2])<lowest:
- name=i[0]
- lowest=eval(i[2])
- print("The lowest shooting percentage team is ",name,str(lowest)+"%")
- print("The second lowest shooting percentage team is ", name2, str(lowest2) + "%")
- print()
- def av_wins(): # function to find the average wins of 30 teams
- file = open("NBAstat.csv")
- reader = csv.reader(file)
- list=[]
- for i in reader:
- list.append(i)
- tot = 0
- j = 0
- while j<len(list):
- tot+=eval(list[j][1])
- j+=1
- return tot/j
- def av_FG(): # function to find the average shooting percentage of 30 teams
- file = open("NBAstat.csv")
- reader = csv.reader(file)
- list = []
- for i in reader:
- list.append(i)
- tot = 0
- h = 0
- while h < len(list):
- tot += eval(list[h][2])
- h += 1
- return tot / h
- def main(): # the main function of all function
- mostWinning()
- lestWinning()
- highPer()
- lowPer()
- main()
- print("the average wins of 30 teams are",av_wins())
- print("the average shooting percentage of 30 teams is",int(av_FG()),"%")
Add Comment
Please, Sign In to add comment