Skip to content

Commit 3cfb87c

Browse files
committed
updated the first question due to the mismatched feature between Runestone main server and MOOC server
1 parent f3e5fbf commit 3cfb87c

File tree

4 files changed

+42
-43
lines changed

4 files changed

+42
-43
lines changed

_sources/_hidden/mc_nested-nt.rst

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,30 @@ Practice
55
:autograde: unittest
66
:nocodelens:
77

8-
Finish the function ``table_reservation(reservation_dict, guest_num)`` below:
9-
- It takes a nested dictionary ``reservation_dict`` representing a restaurant's current reservation situation for a day and a specific number of guests ``guest_num`` as input.
10-
- ``reservation_dict`` is a nested dictionary with outer keys as time slots in a day (e.g., breakfast, lunch, dinner), and values as a list of dictionaries where the inner keys are unique researvation IDs and the values are the number of guests for that reservation.
11-
- Your goal is to count and return the number of reservations in ``reservation_dict`` with the same guest number as the input ``guest_num``.
8+
Finish the function ``add_quantity(item_dict, quantities)`` that “zips” quantities onto their corresponding items inside each category, returning a nested dictionary:
9+
- It takes a dictionary ``item_dict`` and a list ``quantities`` as input, the lengths of ``item_dict`` and ``quantities`` are the same.
10+
- For dict ``item_dict``, keys are category names (strings), values are lists of unique item names (strings), each list contains at least one item (no empty lists).
11+
- For list ``quantities``, it contains the quantity for each item in ``item_dict``. Quantities are given in the same order as the items appear in item_dict when iterated in insertion order, category by category, left to right.
12+
- The total number of quantities equals the total number of items in all categories combined.
13+
- The function should return a new nested dictionary where the outer dictionary keys are the category names, the inner dictionary keys are the item names, and the inner dictionary values are the quantities.
1214

1315
.. table::
14-
:name: nested_merge_course_table
16+
:name: nested_quantity_table
1517
:align: left
1618
:width: 50
1719

18-
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+
19-
| Example Input | Expected Output |
20-
+======================================================================================================================================================================+==================+
21-
|``table_reservation({"breakfast": [{"G01": 3}, {"G02": 4}], "lunch": [{"G03": 2}, {"G04": 4}], "happy_hour": [{"G05": 6}], "dinner": [{"G06": 2}, {"G07": 8}]}, 4)`` | ``2`` |
22-
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+
23-
|``table_reservation({"brunch": [{"G01": 2}], "lunch": [{"G02": 2}, {"G03": 4}], "happy_hour": [{"G04": 2}], "dinner": [{"G05": 2}, {"G06": 8}]}, 2)`` | ``4`` |
24-
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+
25-
|``table_reservation({"breakfast": [{"G01": 1}], "lunch": [{"G02": 2}, {"G03": 4}], "happy_hour": [{"G04": 6}], "dinner": [{"G05": 2}, {"G06": 8}]}, 6)`` | ``1`` |
26-
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+
20+
+--------------------------------------------------------------------------------------+-----------------------------------------------------------------------+
21+
| Example Input | Expected Output |
22+
+======================================================================================+=======================================================================+
23+
|``add_quantity({"Fruits": ["Apples", "Bananas"], "Bakery": ["Bagels"]}, [3, 4, 6])`` | ``{"Fruits": {"Apples": 3, "Bananas": 4}, "Bakery": {"Bagels": 6}}`` |
24+
+--------------------------------------------------------------------------------------+-----------------------------------------------------------------------+
25+
|``add_quantity({"Drinks": ["Coffee", "Tea", "Juice"]}, [10, 5, 7])`` | `` {"Drinks": {"Coffee": 10, "Tea": 5, "Juice": 7}}`` |
26+
+--------------------------------------------------------------------------------------+-----------------------------------------------------------------------+
27+
|``add_quantity({"Dairy": ["Milk"]}, [1])`` | `` {"Dairy": {"Milk": 1}}`` |
28+
+--------------------------------------------------------------------------------------+-----------------------------------------------------------------------+
2729

2830
~~~~
29-
def table_reservation(reservation_dict, guest_num):
31+
def add_quantity(item_dict, quantities):
3032

3133

3234

@@ -42,12 +44,10 @@ Practice
4244
class myTests(TestCaseGui):
4345

4446
def testOne(self):
45-
self.assertEqual(table_reservation({"breakfast": [{"G01": 3}, {"G02": 4}], "lunch": [{"G03": 2}, {"G04": 4}], "happy_hour": [{"G05": 6}], "dinner": [{"G06": 2}, {"G07": 8}]}, 4), 2)
46-
self.assertEqual(table_reservation({"breakfast": [{"G01": 2}, {"G02": 4}], "lunch": [{"G03": 2}, {"G04": 2}], "happy_hour": [{"G05": 6}], "dinner": [{"G06": 2}, {"G07": 8}]}, 2), 4)
47-
self.assertEqual(table_reservation({"breakfast": [{"G01": 2}, {"G02": 4}], "lunch": [{"G03": 2}, {"G04": 2}], "happy_hour": [{"G05": 6}], "dinner": [{"G06": 2}, {"G07": 8}]}, 10), 0)
48-
self.assertEqual(table_reservation({"breakfast": [{"G01": 1}, {"G02": 4}]}, 1), 1)
49-
self.assertEqual(table_reservation({"lunch": [{"G01": 1}, {"G02": 4}], "happy_hour": [{"G01": 1}, {"G02": 4}]}, 1), 2)
50-
self.assertEqual(table_reservation({"breakfast": [{"G02": 4}]}, 9), 0)
47+
self.assertEqual(add_quantity({"Fruits": ["Apples", "Bananas"], "Bakery": ["Bagels"]}, [3, 4, 6]), {"Fruits": {"Apples": 3, "Bananas": 4}, "Bakery": {"Bagels": 6}})
48+
self.assertEqual(add_quantity({"Drinks": ["Coffee", "Tea", "Juice"]}, [10, 5, 7]), {"Drinks": {"Coffee": 10, "Tea": 5, "Juice": 7}})
49+
self.assertEqual(add_quantity({"Bakery": ["Bagel"]}, [12]), {"Bakery": {"Bagel": 12}})
50+
self.assertEqual(add_quantity({"Drinks": ["Coffee", "Tea"]}, [12, 1]), {"Drinks": {"Coffee": 12, "Tea": 1}})
5151
myTests().main()
5252

5353

@@ -63,7 +63,7 @@ Practice
6363
- It returns a dictionary ``average_score`` where keys are student names, and values are the average grades for each student.
6464

6565
.. table::
66-
:name: item_quantity_table
66+
:name: get_average_score_table
6767
:align: left
6868
:width: 50
6969

_sources/_hidden/mc_pre_survey.rst

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,9 @@ What to do next
160160
161161
// if no prev set cookie: generate random condition and set cookie
162162
if (cond != 'wt' && cond != 'nt') {
163-
var v = Math.floor(Math.random() * 2);
164-
if (v < 1) {
165-
cond = 'wt';
166-
} else {
167-
cond = 'nt';
168-
}
169-
setCookie(EXP_COOKIE, cond);
163+
var v = Math.random();
164+
cond = (v < 0.5) ? 'wt' : 'nt';
165+
setCookie(EXP_COOKIE, cond);
170166
}
171167
172168
if (cond == 'wt') {

_sources/_hidden/mc_puzzle_bank.rst

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@
33
:adaptive:
44
:practice: T
55

6-
Finish the function ``table_reservation(reservation_dict, guest_num)`` below:
7-
- It takes a nested dictionary ``reservation_dict`` representing a restaurant's current reservation situation for a day and a specific number of guests ``guest_num`` as input.
8-
- ``reservation_dict`` is a nested dictionary with outer keys as time slots in a day (e.g., breakfast, lunch, dinner), and values as a list of dictionaries where the inner keys are unique researvation IDs and the values are the number of guests for that reservation.
9-
- Your goal is to count and return the number of reservations in ``reservation_dict`` with the same guest number as the input ``guest_num``.
6+
Finish the function ``add_quantity(item_dict, quantities)`` that “zips” quantities onto their corresponding items inside each category, returning a nested dictionary:
7+
- It takes a dictionary ``item_dict`` and a list ``quantities`` as input, the lengths of ``item_dict`` and ``quantities`` are the same.
8+
- For dict ``item_dict``, keys are category names (strings), values are lists of unique item names (strings), each list contains at least one item (no empty lists).
9+
- For list ``quantities``, it contains the quantity for each item in ``item_dict``. Quantities are given in the same order as the items appear in item_dict when iterated in insertion order, category by category, left to right.
10+
- The total number of quantities equals the total number of items in all categories combined.
11+
- The function should return a new nested dictionary where the outer dictionary keys are the category names, the inner dictionary keys are the item names, and the inner dictionary values are the quantities.
1012
-----
11-
def table_reservation(reservation_dict, guest_num):
13+
def add_quantity(item_dict, quantities):
1214
=====
13-
count = 0
15+
index = 0
16+
result = {}
17+
=====
18+
for category, items in item_dict.items():
1419
=====
15-
for time_slot, reservations in reservation_dict.items():
20+
result[category] = {}
1621
=====
17-
for reservation in reservations:
22+
for item in items:
1823
=====
19-
for reservation_id, guests in reservation.items():
24+
result[category][item] = quantities[index]
2025
=====
21-
if guests == guest_num:
26+
index += 1
2227
=====
23-
count += 1
24-
=====
25-
return count
28+
return result
2629

2730

2831
.. parsonsprob:: p2-mooc_nested

_sources/_hidden/mc_start.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Python 3 with Nested Dictionaries
22
=====================================
33
Welcome to the Python 3 with Nested Dictionaries study!
44
This study is part of a research project at the University of Michigan, and your participation will contribute to our understanding of how students learn programming concepts.
5-
We are researchers at University of Michigan who are trying to improve the teaching and learning of programming.
5+
We are researchers at the University of Michigan who are trying to improve the teaching and learning of programming.
66

77
Purpose of this Study
88
^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)