Eile Edit view Hbtory Bookmarks bols Help a sakaieURIcsc 110

Eile Edit view Hbtory Bookmarks bols Help a sakaieURI:csc 110.. x Olab5-files-f16 labs-... x 4. Functions-How to T. x a ARGUMENT -The Ri.. x C Free Sports Ficks-T.. x Free Plcks Daily Fre.. x Rhttply home. series txt x CChogg studyIGuide. x C write In Python ldlo.. x https sakai. item/11693724/group/e3dbb580-16f5-49of affo-88196032a87c/Labs/Lab 5 working h Files 10 7 lab5-files-f16 pdf. e Q, chegg D t Page. 2 of World Series Baseball (Points 100 Given a text file that stores the World Series winners and losers for the years 1903 to 2015, write a program that allows a user do the following 1 Find the World Series winner for a particular year 2 Find the World Series loser for a particular year 3 Count the number of times a team has won the World Series You can get the text file here: http:// uri.edu/ cingiser/cse110/labs/python/worldseries.txt Your program should allow the user to continue to enter choices until he/she is finished. To get you started, download this python code: http:// 110 /lab th ld Part A: Run the program u point Save the Python file and the text file both to the same location on the computer. Run the program in IDLE to see how it should work. You will notice that it runs, but does not do anything except execute the main function and the getChoice function

Solution

# World Series Results

# Given a file with the World Series Champions since 1904
# Allow user to ask various questions about the results
win = []
yr = []
lsr = []
def findWinnerAndLoser(year):
try:
year = int(year)
except ValueError:
print(\"Please enter an integer\")
return -1,-1
if year in yr:
pl = yr.index(year)
return win[pl],lsr[pl]
else:
print(\"We do not have the data for that year.\")
return -1,-1
def countWins(team):
count = 0
for l in win:
if l == team:
count+=1
return count
def countLosses(team):
count = 0
for l in lsr:
if l == team:
count+=1
return count
def greatestWins():
mx=0
team = \"\"
for l in win:
if countWins(l) > mx:
mx = countWins(l)
team = l
return mx,team
def greatestLosses():
mx=0
team = \"\"
for l in lsr:
if countWins(l) > mx:
mx = countLosses(l)
team = l
return mx,team
def getChamps():
# This function will get the data from the data file - be sure to look at the format of the data in the
# file and read each line as we did with the phone search program in class.
# The function should return the list of years, the list of winners and the list of losers
  
f = open(\"worldseries.txt\",\'r\')
for line in f.readlines():
line = line[0:-1]
line = line.split(\',\')
yr.append(int(line[0]))
win.append(line[1])
lsr.append(line[2])
#print(\"\")
#print(\"This is where you will get the data from the data file\")
#print(\"\")
# Make sure to return the correct information from this function
return

def getChoice():
# This function displays the menu of choices for the user
# It reads in the user\'s choice and returns it as an integer
print(\"\")
print(\"Make a selection from the following choices:\")
print(\"1 - Find the World Series Winner and Loser for a particular year\")
print(\"2 - Count how many times a team has won the World Series\")
print(\"3 - Find the team that has won the most World Series Championships\")
print(\"4 - Find the team that has lost the most World Series Championships\")
print(\"5 - Quit\")
try:
choice = int(input(\"Enter your choice --> \"))
except ValueError:
print(\"Please enter an integer\")
return -1
print(\"\")
return choice


def main():
# Call the function to get the data from the data file and store the results in three lists
getChamps()
choice = getChoice()
while choice != 5:
if choice == 1:
year = input(\"Enter the year to search for: \")
# Call the function to get the winner and the loser
win,loser = findWinnerAndLoser(year)
if(win==-1):
choice = getChoice()
continue
print(\"The winner for \"+str(year)+\" was \"+win)
print(\"The loser for \"+str(year)+\" was \"+loser)
choice = getChoice()
elif choice == 2:
team = input(\"Enter the team name: \")
# Call the function to get the number of wins for the team
print(team+\" won the World Series \"+str(countWins(team))+\" times.\")
choice = getChoice()
elif choice == 3:
# Call the function to find the team that won the most championships
mx,team = greatestWins()
print(team+\" won the World Series the most at \"+str(mx)+\" times.\")
choice = getChoice()
elif choice == 4:
# Call the function to find the team that lost the most championships
mx,team = greatestLosses()
print(team+\" lost the World Series the most at \"+str(mx)+\" times.\")
choice = getChoice()
else:
print(\"Error in your choice\")
choice = getChoice()
print(\"Good-bye\")
main()

 Eile Edit view Hbtory Bookmarks bols Help a sakaieURI:csc 110.. x Olab5-files-f16 labs-... x 4. Functions-How to T. x a ARGUMENT -The Ri.. x C Free Sports Fick
 Eile Edit view Hbtory Bookmarks bols Help a sakaieURI:csc 110.. x Olab5-files-f16 labs-... x 4. Functions-How to T. x a ARGUMENT -The Ri.. x C Free Sports Fick
 Eile Edit view Hbtory Bookmarks bols Help a sakaieURI:csc 110.. x Olab5-files-f16 labs-... x 4. Functions-How to T. x a ARGUMENT -The Ri.. x C Free Sports Fick

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site