{"assignment":{"_schema_version":2,"course_id":37,"date_created":"2022-06-28T19:00:00+00:00","date_modified":"2022-08-10T20:17:18.138376+00:00","extra_instructor_files":"","extra_starting_files":"","forked_id":null,"forked_version":null,"hidden":false,"id":1155,"instructions":"{\n  \"settings\": {\n    \"readingId\": \"bakery_if_patterns_read\"\n  },\n  \"questions\": {\n    \"DefinePatterns\": {\n      \"type\": \"matching_question\",\n      \"points\": 3,\n      \"body\": \"Match each explanation to the most relevant pattern\",\n      \"answers\": [\n        \"And vs Nested If\",\n        \"Defensive Guard\",\n        \"Early Return\",\n        \"Multiple Return Spots\",\n        \"Build-Up-Return\",\n        \"Define-and-Refine\"\n      ],\n      \"statements\": [\n        \"An `if` statement with an `and` can be replaced with two `if` statements, one inside the other.\",\n        \"Wrap some code with an `if` statement so that errors are not caused in certain conditions.\",\n        \"Return a value from a function if a condition is not met, in order to avoid errors.\",\n        \"Return a value from a function with many `if`/`elif`/`else` branches by putting `return` statements in each branch.\",\n        \"Return a value from a function with many `if`/`elif`/`else` branches by updating a variable and then only having one `return` statement at the end.\",\n        \"Avoid having multiple `else` branches to specify default behavior by assinging an initial value to a variable prior to the `if` statements.\"\n      ]\n    },\n    \"DescribeMultipleReturnBehavior\": {\n      \"type\": \"multiple_answers_question\",\n      \"points\": 3,\n      \"body\": \"What happens when there are multiple `return` statements in a function?\",\n      \"answers\": [\n        \"The program ends when the first `return` statement is reached.\",\n        \"The function ends when the first `return` statement is reached.\",\n        \"An error will occur, because you cannot have more than one `return` statement.\",\n        \"The last `return` statement will be used to determine the returned value.\",\n        \"All the values from all the `return` statements will be combined using the type rules.\",\n        \"The `return` statements must be placed under other control structures like `if` statements, or the other `return` statements will not be reachable.\"\n      ]\n    },\n    \"JustifyBuildUpPattern\": {\n      \"type\": \"multiple_answers_question\",\n      \"points\": 3,\n      \"body\": \"Why might you use the Build-Up-Return pattern instead of the Multiple-Returns pattern?\",\n      \"answers\": [\n        \"The Build-Up-Return pattern only has one `return` statement, so the control flow is a little less complicated.\",\n        \"The Build-Up-Return pattern often leads to shorter code\",\n        \"The Build-Up-Return pattern often leads to faster code\",\n        \"The Build-Up-Return pattern guarantees that a value will be returned no matter what, unlike the Multiple-Returns where you might forget to return a value from a branch.\",\n        \"The Multiple-Returns pattern is not functionally equivalent to the Build-Up-Return pattern, so that pattern is more powerful.\"\n      ]\n    },\n    \"UseDefensiveGuard\": {\n      \"type\": \"multiple_answers_question\",\n      \"points\": 3,\n      \"body\": \"In which of these cases might you need a Defensive Guard to avoid an error?\",\n      \"answers\": [\n        \"Make sure that a value is not zero before division\",\n        \"Make sure a string contains only digits, before you convert it to an integer\",\n        \"Make sure an integer is positive, before you convert it to a string\",\n        \"Make sure a boolean value is True, before you invert it with `not`\",\n        \"Make sure that a string has at least one character, before you index the first character\",\n        \"Make sure that a string has at least 5 characters, before you subscript the first ten characters\"\n      ]\n    },\n    \"RelateLogicalPatterns\": {\n      \"type\": \"multiple_answers_question\",\n      \"points\": 2,\n      \"body\": \"Which of these comparions between the patterns are accurate?\",\n      \"answers\": [\n        \"The Early Return and Defensive Guard patterns are similar, since they both avoid problematic code with an `if` statement.\",\n        \"The \\\"And vs Nested If\\\" pattern is similar to the \\\"Defensive Guard\\\", since one incorporates the `and` operator and the other incorporates the `or` operator\",\n        \"The Build-Up-Return pattern and the Multiple Return Spots patterns are similar, since they both achieve the same result.\",\n        \"The Define-and-Refine pattern is useful for specifying default behavior to avoid having too many branches, just like the Multiple Returns pattern.\"\n      ]\n    },\n    \"PredictNestedIf\": {\n      \"type\": \"short_answer_question\",\n      \"points\": 1,\n      \"body\": \"In the following code, what will be printed?\\n\\n```python\\nalpha = 20\\nbeta = 3\\n\\nif alpha > 10:\\n    if beta > 10:\\n        alpha = 10\\n\\nprint(alpha)\\n```\"\n    },\n    \"DeterminePatternEquivalency\": {\n      \"type\": \"multiple_answers_question\",\n      \"points\": 2,\n      \"body\": \"Given the following code:\\n\\n```python\\ngamma = \\\"Hello!\\\"\\nif gamma and gamma[-1] == \\\"!\\\":\\n    print(\\\"Exclaim\\\")\\n```\\n\\nWhich of the following programs are functionally equivalent to the conditional part?\\n```python\\n#A\\nif len(gamma) > 0 and gamma[-1] == \\\"!\\\":\\n    print(\\\"Exclaim\\\")\\n``` \\n```python\\n#B\\nif gamma or gamma[-1] == \\\"!\\\":\\n    print(\\\"Exclaim\\\")\\n``` \\n```python\\n#C\\nif gamma:\\n  if gamma[-1] == \\\"!\\\":\\n    print(\\\"Exclaim\\\")\\n``` \\n```python\\n#D\\nif gamma:\\n  print(\\\"Exclaim\\\")\\nif gamma[-1] == \\\"!\\\":\\n  print(\\\"Exclaim\\\")\\n``` \\n```python\\n#E\\nif gamma:\\n  print(\\\"Exclaim\\\")\\nelif gamma[-1] == \\\"!\\\":\\n  print(\\\"Exclaim\\\")\\n```\",\n      \"answers\": [\n        \"A\",\n        \"B\",\n        \"C\",\n        \"D\",\n        \"E\"\n      ]\n    }\n  }\n}","ip_ranges":"","name":"3B2) Logical Patterns","on_change":"","on_eval":"","on_run":"","owner_id":1,"owner_id__email":"acbart@udel.edu","points":1,"public":true,"reviewed":false,"sample_submissions":[],"settings":"","starting_code":"","subordinate":false,"tags":[],"type":"quiz","url":"bakery_if_patterns_quiz","version":2},"ip":"216.73.216.157","submission":{"_schema_version":3,"assignment_id":1155,"assignment_version":2,"attempts":0,"code":"","correct":false,"course_id":37,"date_created":"2026-05-20T14:01:40.823214+00:00","date_due":"","date_graded":"","date_locked":"","date_modified":"2026-05-20T14:01:40.823214+00:00","date_started":"","date_submitted":"","endpoint":"","extra_files":"","feedback":"","grading_status":"NotReady","id":2036900,"score":0.0,"submission_status":"Started","time_limit":"","url":"submission_url-f99bb284-7429-4815-ab2c-d95da880843a","user_id":2044668,"user_id__email":"","version":0},"success":true}
