Question: I am working on a Python program that allows the user to enter a sport and team to get info on the last 4 games.
I am working on a Python program that allows the user to enter a sport and team to get info on the last 4 games. The user is supposed to fully type out the sport and team, but if they do not enter it correctly or they enter a sport or team that is not in the list, it is supposed to give them list options. I am having issues with the program running my functions in order. Instead of starting like so:
Welcome to the Sport Scores Index! Enter a sport:
It is printing like this:
Enter a sport: does not exist. Enter one of the following sports: 1. NHL 2. College Basketball 3. NBA
Also, when I do choose a sport and team, it is not printing out the games but it's printing this:
1. NHL 2. College Basketball 3. NBA NBA Enter a team: oirghsa oirghsa does not exist. Choose from the following teams: Choose a team: 1. Philadelphia 76ers 2. Los Angeles Lakers 3. Washington Wizards Enter a team: Philadelphia 76ers Philadelphia 76ers does not exist. Choose from the following teams: Choose a team:
I know there are some issues with my code and I am going through it, but could someone guide me through some of the issues in my code? I just need help debugging. Thank you. The code is below:
allTeams = [ # list all teams and game info [1, 'NHL', 'Boston Bruins', '2/25/2021', 'New York Islanders', 2, 7, 'Lost'], [2, 'NHL', 'Boston Bruins', '2/21/2021', 'Philadelphia Flyers', 7, 3, 'Won'], [3, 'NHL', 'Boston Bruins', '2/18/2021', 'New Jersey Devils', 2, 3, 'Lost'], [4, 'NHL', 'Boston Bruins', '2/13/2021', 'New York Islanders', 2, 4, 'Lost'], [5, 'NHL', 'New York Rangers', '2/24/2021', 'Philadelphia Flyers', 3, 4, 'Lost'], [6, 'NHL', 'New York Rangers', '2/20/2021', 'Washington Capitals', 4, 1, 'Won'], [7, 'NHL', 'New York Rangers', '2/18/2021', 'Philadelphia Flyers', 3, 2, 'Won'], [8, 'NHL', 'New York Rangers', '2/16/2021', 'New Jersey Devils', 2, 5, 'Lost'], [9, 'NHL', 'Detroit Red Wings', '2/25/2021', 'Nashville Predators', 5, 2, 'Won'], [10, 'NHL', 'Detroit Red Wings', '2/23/2021', 'Nashville Predators', 0, 2, 'Lost'], [11, 'NHL', 'Detroit Red Wings', '2/20/2021', 'Florida Panthers', 2, 1, 'Won'], [12, 'NHL', 'Detroit Red Wings', '2/19/2021', 'Florida Panthers', 2, 7, 'Lost'], [13, 'College Basketball', 'Rutgers Scarlet Knights', '2/24/2021', 'Indiana Hoosiers', 74, 63, 'Won'], [14, 'College Basketball', 'Rutgers Scarlet Knights', '2/21/2021', 'Maryland Terrapns', 59, 68, 'Lost'], [15, 'College Basketball', 'Rutgers Scarlet Knights', '2/18/2021', 'Michigan Wolverines', 64, 71, 'Lost'], [16, 'College Basketball', 'Rutgers Scarlet Knights', '2/13/2021', 'Northwestern Wildcats', 64, 50, 'Won'], [17, 'College Basketball', 'Villanova Wildcats', '2/28/2021', 'Butler Bulldogs', 61, 73, 'Lost'], [18, 'College Basketball', 'Villanova Wildcats', '2/23/2021', 'St Johns Red Storm', 81, 58, 'Won'], [19, 'College Basketball', 'Villanova Wildcats', '2/20/2021', 'Uconn Huskies', 68, 60, 'Won'], [20, 'College Basketball', 'Villanova Wildcats', '2/13/2021', 'Chreighton Bluejays', 70, 86, 'Lost'], [21, 'College Basketball', 'Duke Blue Devils', '2/22/2021', 'Syracuse Orange', 85, 71, 'Won'], [22, 'College Basketball', 'Duke Blue Devils', '2/20/2021', 'Virginia Cavaliers', 66, 65, 'Won'], [23, 'College Basketball', 'Duke Blue Devils', '2/17/2021', 'Wake Forest Demon Decons', 84, 60, 'Won'], [24, 'College Basketball', 'Duke Blue Devils', '2/13/2021', 'NC State Wolfpack', 69, 53, 'Won'], [24, 'NBA', 'Philadelphia 76ers', '2/25/2021', 'Dallas Mavericks', 111, 97, 'Won'], \ [25, 'NBA', 'Philadelphia 76ers', '2/23/2021', 'Toronto Raptor', 109, 101, 'Won'], [26, 'NBA', 'Philadelphia 76ers', '2/21/2021', 'Toronto Raptor', 103, 110, 'Lost'], [27, 'NBA', 'Philadelphia 76ers', '2/19/2021', 'Chicago Bulls', 112, 105, 'Won'], [28, 'NBA', 'Los Angeles Lakers', '2/24/2021', 'Utah Jazz', 114, 89, 'Lost'], [29, 'NBA', 'Los Angeles Lakers', '2/22/2021', 'Washington Wizards', 124, 127, 'Lost'], [30, 'NBA', 'Los Angeles Lakers', '2/20/2021', 'Miami Heat', 96, 94, 'Lost'], [31, 'NBA', 'Los Angeles Lakers', '2/18/2021', 'Brooklyn Nets', 109, 98, 'Lost'], [32, 'NBA', 'Washington Wizards', '2/25/2021', 'Denver Nuggets', 112, 110, 'Won'], [33, 'NBA', 'Washington Wizards', '2/23/2021', 'LA Clippers', 116, 135, 'Lost'], [34, 'NBA', 'Washington Wizards', '2/22/2021', 'Los Angeles Lakers', 127, 124, 'Won'], [35, 'NBA', 'Washington Wizards', '2/20/2021', 'Portland Trail Blazers', 118, 111, 'Won'] ] # for each course in the "allTeams" list for teams in allTeams: # assign values to variables teamID = teams[0] sportType = teams[1] teamName = teams[2] gameDate = teams[3] opposingTeam = teams[4] teamScore = teams[5] opposingScore = teams[6] wonLost = teams[7] def repeat(): # loops to allow user to search again print(" Would you like to search another sport? Y or N") repeat_input = str(input()) if repeat_input == "Y": return main() elif repeat_input == "N": print(" Thank you for using the Sports Scores Index!") def team(): # allows user to choose sport print(" Enter one of the following sports: ") print("1. NHL " "2. College Basketball " "3. NBA ") sport_input = str(input()) if sport_input == "NHL": return nhl(teamName, gameDate, opposingTeam, teamScore, opposingScore, wonLost) elif sport_input == "College Basketball": return college_bball(teamName, gameDate, opposingTeam, teamScore, opposingScore, wonLost) elif sport_input == "NBA": return nba(teamName, gameDate, opposingTeam, teamScore, opposingScore, wonLost) else: print("Invalid choice. Please try again.") return team() def nhl(teamName, gameDate, opposingTeam, teamScore, opposingScore, wonLost): # gives user info about nhl print(" Enter a team: ") user_input = str(input()) search = user_input for sublist in allTeams: if sublist[1] == search: print("The ", teamName, " ", wonLost, " to ", opposingTeam, " ", teamScore, " to ", opposingScore, " on ", gameDate) print(" Would you like to search another sport? Y or N") return repeat() else: print(user_input, " does not exist. Choose from the following teams:") print("1. Boston Bruins " "2. New York Rangers " "3. Detroit Red Wings ") return nhl(teamName, gameDate, opposingTeam, teamScore, opposingScore, wonLost) def college_bball(teamName, gameDate, opposingTeam, teamScore, opposingScore, wonLost):# show info about college basketball print(" Enter a team: ") user_input = str(input()) search = user_input for sublist in allTeams: if sublist[1] == search: print("The ", teamName, " ", wonLost, " to ", opposingTeam, " ", teamScore, " to ", opposingScore, " on ", gameDate) return repeat() else: print(user_input, " does not exist. Choose from the following teams:") print(" Choose a team: ") print("1. Rutgers Scarlet Knights " "2. Villanova Wildcats " "3. Duke Blue Devils ") return college_bball(teamName, gameDate, opposingTeam, teamScore, opposingScore, wonLost) def nba(teamName, gameDate, opposingTeam, teamScore, opposingScore, wonLost): #shows info about NBA print(" Enter a team: ") user_input = str(input()) search = user_input for sublist in allTeams: if sublist[1] == search: print("The ", teamName, " ", wonLost, " to ", opposingTeam, " ", teamScore, " to ", opposingScore, " on ", gameDate) return repeat() else: print(user_input, " does not exist. Choose from the following teams:") print(" Choose a team: ") print("1. Philadelphia 76ers " "2. Los Angeles Lakers " "3. Washington Wizards ") return nba(teamName, gameDate, opposingTeam, teamScore, opposingScore, wonLost) def main(): # main function while (True): sport_input = str(" Enter a sport: ") if (sport_input == sportType): team_input = str(" Enter a team: ") search = team_input for sublist in allTeams: if sublist[1] == search: print("The ", teamName, " ", wonLost, " to ", opposingTeam, " ", teamScore, " to ", opposingScore, " on ", gameDate) return repeat() else: print(team_input, " does not exist. ") return team() else: print(sport_input, "does not exist.") return team() if __name__ == '__main__': main() Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
