Published using Google Docs
CSE 160 Final Exam (22au) - Part 1
Updated automatically every 5 minutes

CSE 160 Final Exam (22au) - Part 1

Note: For all three problems, you should NOT modify any of the input parameters.

Problem 1:

It's your job to set up matches for a soccer tournament! However, you want to set up matches such that your team is most likely to win. To do this, you secretly create a match between your team and the opponent with the lowest winning average. Write a function create_match(my_team, score_sheet) with the following arguments:

create_match should return a tuple where the first item is the team name you would choose as an opponent for your team to play and the second item is the winning average of that team.

A team's winning average is computed by calculating the percentage of a team's matches that were won. That is: number of matches won/(number of matches won + number of matches lost)

You may assume that:

Given: scores1 = {"USA": (["France", "Brazil"],["Korea"]),

            "France": (["Brazil"], ["USA"]),

            "Brazil": (["Korea"], ["France", "USA"]),

           "Korea": (["USA"], ["Brazil"])}

a call to create_match("USA", scores1) would return ("Brazil", 0.33333) because France has a winning average of 0.5 since they won half their matches, Brazil has a winning average of 0.33333, since they lost two matches and won one, and Korea also has a winning average of 0.5  since they won one match and lost the other. Therefore, you will pair the USA up with Brazil, which has the lowest winning average.

Given: scores2 = {"USA": (["France"], []),

     "France": ([], ["USA"])}

a call to create_match("USA", score_sheet) would return ("France", 0) because there is only one other team, so France has the lowest winning average by default, with 0 games out of 1 won to give them a winning average of 0.

Problem 2:

Write a function search_item(inventory, search_terms, num_match) with the following arguments:

search_item should return an alphabetically sorted list of items from inventory that have greater than or equal to num_match descriptive terms from search_terms in their list of descriptive terms.

You may assume that:

Given:

inventory = {"banana": ["yellow", "long", "Fruit"],

  "pole": ["long", "plastic"],

  "yellow wig": ["wavy", "hair", "long", "yellow"],

  "chair": ["furniture", "brown"]}

search_terms = ["long", "yellow", "Fruit", "tangy"]

A call to search_item(inventory, search_terms, 2) should return ["banana", "yellow wig"] because both terms contain at least two of the terms in search_terms in their list of descriptive terms. ("banana" has three of the terms from search_terms in its list of descriptive terms and"yellow wig" has two.)

A call to search_item(inventory, search_terms, 4) should return [] because none of the items in inventory contain all four terms in search_terms in their list of descriptive terms.

Problem 3:

Write a function todo_list(tasks)with the following argument:

todo_list returns a list of uncompleted tasks' "name" values sorted by "priority" and "time req" (see more on what to do in the case of ties below).

You may assume that:

Given: tasks_lst1 =

[{"name": "CSE160 HW6", "priority": 1, "time req": 90, "completed": True},

 {"name": "Grocery shopping", "priority": 2, "time req": 20, "completed": False},

 {"name": "Doing the Laundry", "priority": 1, "time req": 60, "completed": False},

 {"name": "Water plants", "priority": 2, "time req": 10, "completed": False}]

Calling todo_list(tasks_lst1) should return ["Doing the Laundry", "Water plants", "Grocery shopping"]. The task "CSE160 HW6" is not included because it is completed, and "Water plants" is placed before "Grocery shopping" because although they both have priority 2, the time required for "Water plants" is less than for "Grocery shopping".

Given: tasks_lst2 =

[{"name": "Eating Lunch", "priority": 1, "time req": 30, "completed": True},

 {"name": "Doing the dishes", "priority": 2, "time req": 10, "completed": False},

 {"name": "Making Lunch", "priority": 1, "time req": 30, "completed": True}]

Calling todo_list(tasks_lst2) should return ["Doing the dishes"]. This is because all other tasks have been completed.

---------------------  End  of part 1 ------------------

Don't forget to do part 2!