Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

team=list(); won=list(); lost=list(); pct=list(); count=0; with open(\"file.txt\

ID: 3867192 • Letter: T

Question

team=list(); won=list(); lost=list(); pct=list(); count=0; with open("file.txt") as file:#file.txt is the input file to be read data = file.readlines() for line in data : cleanedLine = line.strip().split(); line=cleanedLine; if count!=0: team.append(line[0]); won.append(line[1]); lost.append(line[2]); pct.append(line[3]); count=1; def fun( pct, count):# soting the list based on percentage for i in range(0,count): for j in range(i+1,count): if (pct[i] < pct[j]): tempname = team[i]; tempwins = won[i]; templosses = lost[i]; tempper = pct[i]; team[i]= team[j]; won[i] = won[j]; lost[i] = lost[j]; pct[i] = pct[j]; team[j] = tempname; won[j] = tempwins; lost[j] = templosses; pct[j] = tempper; fun(pct,len(pct)); thefile = open('test.txt', 'w');#test.txt is the output file for i in range(0,len(pct)): thefile.write(team[i]+" "+won[i]+" "+lost[i]+" "+pct[i]); thefile.write(" "); I am missing something this program will not run properly. I am getting an error message (expected an indented block) Baseball. Write a program to use the file to produce a text file containing the information listed above. In the new file, the baseball teams should be in descending order by the percentage of games won. Complete your program design (flow chart, pseudocode, or other) Save the finished project as a .pyfile Team Won Lost Pct Baltimore 94 44 0.593 Newyork 84 78 0.519 Toronto 83 79 0.512 TampaBay 77 85 0.475 Boston 71 91 0.438

Explanation / Answer

#!usr/bin/python

team = []
wins = []
losses = []
pct = []

with open("file1.txt") as file:
   count = 0;
   for line in file:
       if "Team" in line:
          continue
       team.append(line.split()[0])
       wins.append(line.split()[1])
       losses.append(line.split()[2])
       pct.append(line.split()[3])
       count = count + 1
   for i in range(count):
       print(team[i], wins[i], losses[i], pct[i])
   for i in range(count):
       for j in range(i+1, count, 1):
           if pct[i] < pct[j]:
              temp = team[i]
              team[i] = team[j]
              team[j] = temp
              temp1 = wins[i]
              wins[i] = wins[j]
              wins[j] = temp1
              temp1 = losses[i]
              losses[i] = losses[j]
              losses[j] = temp1
              temp2 = pct[i]
              pct[i] = pct[j]
              pct[j] = temp2
   print('The sorted descending order is as follows')
   file1 = open("test.txt", 'w')  
   for i in range(count):
       print(team[i], wins[i], losses[i], pct[i])
       file1.write(team[i] + " " + wins[i] + " " + losses[i] + " " + pct[i] + " ")
   file1.close()