Question: I need help with a program in Python. Source Code is also below The file needed - WorldSeriesWinners.txt - is included below Read the data

I need help with a program in Python. Source Code is also below

  • The file needed - WorldSeriesWinners.txt - is included below
  • Read the data from this file directly into a list.
  • Allow the user to enter the name of a team and then display the number of times the team has won
  • Use the in and/or not in operators in your solution
  • Do not use Dictionaries

Source Code:

##Function that reads data from file and puts in in the wSWList def readFromFile(): ##wSWList Initialization wSWList =[] ##Open WorldSeriesWinners.txt for reading winnersFile = open('WorldSeriesWinners.txt','r') ##Read a line and assign to yearlyWinners yearlyWinners = winnersFile.readline() ##While loop for reading the file and appending to list while yearlyWinners != '': yearlyWinners = yearlyWinners.rstrip(' ') wSWList.append(yearlyWinners) yearlyWinners = winnersFile.readline() ##return wSWList return wSWList

winnersFile.close()

def numOfWins(teamName,wSWList): numOfWins =0 for index in range(len(wSWList)): if wSWList[index] == teamName: numOfWins+=1 return numOfWins

def main(): wSWList = readFromFile() teamName =input('Enter the team name you are looking for: ') numberOfWins = numOfWins(teamName,wSWList) print(teamName,'won the World Series ',numberOfWins,'times')

main()

File Data:

Detroit Tigers New York Mets Baltimore Orioles Pittsburgh Pirates Oakland Athletics Oakland Athletics Oakland Athletics Cincinnati Reds Cincinnati Reds New York Yankees New York Yankees Pittsburgh Pirates Philadelphia Phillies Los Angeles Dodgers St. Louis Cardinals Baltimore Orioles Detroit Tigers Kansas City Royals New York Mets Minnesota Twins Los Angeles Dodgers Oakland Athletics Cincinnati Reds Minnesota Twins Toronto Blue Jays Toronto Blue Jays Atlanta Braves New York Yankees Florida Marlins New York Yankees New York Yankees New York Yankees Arizona Diamondbacks Anaheim Angels Florida Marlins Boston Red Sox Chicago White Sox St. Louis Cardinals Boston Red Sox Philadelphia Phillies

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!