In the cell below is a list of tuples, where each tuple is of the form (year, name-of-hockey-team) or (int, str). The data contained in
In the cell below is a list of tuples, where each tuple is of the form (year, name-of-hockey-team) or (int, str). The data contained in the list is of Stanley Cup winners since 1927.
If you use shift-enter within that cell, the list will become part of this notebook's variable definitions and will afterards be accessible in any other code cell.
STANLEY_CUP_WINNERS = [(2018, 'Washington Capitals'), (2017, 'Pittsburgh Penguins'), (2016, 'Pittsburgh Penguins'), (2015, 'Chicago Blackhawks'), (2014, 'Los Angeles Kings'), (2013, 'Chicago Blackhawks'), (2012, 'Los Angeles Kings'), (2011, 'Boston Bruins'), (2010, 'Chicago Blackhawks'), (2009, 'Pittsburgh Penguins'), (2008, 'Detroit Red Wings'), (2007, 'Anaheim Ducks'), (2006, 'Carolina Hurricanes'), (2004, 'Tampa Bay Lightning'), (2003, 'New Jersey Devils'), (2002, 'Detroit Red Wings'), (2001, 'Colorado Avalanche'), (2000, 'New Jersey Devils'), (1999, 'Dallas Stars'), (1998, 'Detroit Red Wings'), (1997, 'Detroit Red Wings'), (1996, 'Colorado Avalanche'), (1995, 'New Jersey Devils'), (1994, 'New York Rangers'), (1993, 'Montreal Canadiens'), (1992, 'Pittsburgh Penguins'), (1991, 'Pittsburgh Penguins'), (1990, 'Edmonton Oilers'), (1989, 'Calgary Flames'), (1988, 'Edmonton Oilers'), (1987, 'Edmonton Oilers'), (1986, 'Montreal Canadiens'), (1985, 'Edmonton Oilers'), (1984, 'Edmonton Oilers'), (1983, 'New York Islanders'), (1982, 'New York Islanders'), (1981, 'New York Islanders'), (1980, 'New York Islanders'), (1979, 'Montreal Canadiens'), (1978, 'Montreal Canadiens'), (1977, 'Montreal Canadiens'), (1976, 'Montreal Canadiens'), (1975, 'Philadelphia Flyers'), (1974, 'Philadelphia Flyers'), (1973, 'Montreal Canadiens'), (1972, 'Boston Bruins'), (1971, 'Montreal Canadiens'), (1970, 'Boston Bruins'), (1969, 'Montreal Canadiens'), (1968, 'Montreal Canadiens'), (1967, 'Toronto Maple Leafs'), (1966, 'Montreal Canadiens'), (1965, 'Montreal Canadiens'), (1964, 'Toronto Maple Leafs'), (1963, 'Toronto Maple Leafs'), (1962, 'Toronto Maple Leafs'), (1961, 'Chicago Blackhawks'), (1960, 'Montreal Canadiens'), (1959, 'Montreal Canadiens'), (1958, 'Montreal Canadiens'), (1957, 'Montreal Canadiens'), (1956, 'Montreal Canadiens'), (1955, 'Detroit Red Wings'), (1954, 'Detroit Red Wings'), (1953, 'Montreal Canadiens'), (1952, 'Detroit Red Wings'), (1951, 'Toronto Maple Leafs'), (1950, 'Detroit Red Wings'), (1949, 'Toronto Maple Leafs'), (1948, 'Toronto Maple Leafs'), (1947, 'Toronto Maple Leafs'), (1946, 'Montreal Canadiens'), (1945, 'Toronto Maple Leafs'), (1944, 'Montreal Canadiens'), (1943, 'Detroit Red Wings'), (1942, 'Toronto Maple Leafs'), (1941, 'Boston Bruins'), (1940, 'New York Rangers'), (1939, 'Boston Bruins'), (1938, 'Chicago Blackhawks'), (1937, 'Detroit Red Wings'), (1936, 'Detroit Red Wings'), (1935, 'Montreal Maroons'), (1934, 'Chicago Blackhawks'), (1933, 'New York Rangers'), (1932, 'Toronto Maple Leafs'), (1931, 'Montreal Canadiens'), (1930, 'Montreal Canadiens'), (1929, 'Boston Bruins'), (1928, 'New York Rangers'), (1927, 'Ottawa Senators')]
Your task for part A of assignment #4 is to complete the functions winning_years and main in the code cell below. Below is a transcript of two executions of the completed code.
What team are you searching for? Los Angeles Kings 2012 2014 What team are you searching for? Vancouver Canucks Has not yet won the Stanley Cup
You need not worry whether or not the team entered is a real NHL team (although Anaheim Mighty Ducks still sounds wrong to someone who remembers when Wayne Gretzky was a rookie player in the WHA).
Do not use any libraries for this assignment other than the standard library (i.e., no use of NumPy, SciPy, pandas, etc. is permitted)
def winning_years(query_team): """ function: winning_years Using a global list of tuples of the form (year, team name) that corresponds to Stanley Cup winners since 1927, and given an input parameter corresponding the team for which we are completing this query, the functions finds all years for which that team has won the Stanley Cup. The years are returned in a list. Note that the code here may use STANLEY_CUP_WINNERS as a global variable (i.e., it need not be passed into the function as a parameter). Input: ------ * query_team: The team name which will be used to look through the list of Stanley Cup winners. Output: -------- * A (possibly empty) list of integers that are the years in which the query_team has won the Stanley Cup. """
def main(): """ Query the user for the name of team for which you are looking for Stanley Cup years. Call winning_years with this team name; if the list returned is empty, print "Has not yet won the Stanley Cup"; if the list is not empty, print each year on its own line. """
main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started