{"assignment":{"_schema_version":2,"course_id":37,"date_created":"2022-06-28T19:00:00+00:00","date_modified":"2023-08-26T14:05:22.727837+00:00","extra_instructor_files":"","extra_starting_files":"","forked_id":null,"forked_version":null,"hidden":false,"id":962,"instructions":"## Purpose\n\n![A picture of a computer with the word \"ERROR!\" displayed on its monitor.](intro_errors_confused.png)\n\nWhen something goes wrong with your program, Python will give you an error message.\nThese messages are meant to help you find where your error is and what kind of error it is.\n\n## Types of Error Messages\n\n- `NameError`\n- `ImportError`\n- `ValueError`\n- `TypeError`\n- `UnboundLocalError`\n- and more...\n\nPython has many, many error messages.\nIt can take a long time to learn them all.\nWhen you encounter an error message you are unfamiliar with, you should first read and think about the message.\nIf you are not sure what it means, you should look up the error's meaning in the documentation.\nThen, you can debug your program.\nThe following list is just a small subset of all the different kinds of errors.\n\n## Terminology\n\n* Error\n* Exception\n\nJust a minor point of terminology.\nErrors are sometimes referred to as _exceptions_.\nThey're not quite identical, but for our purposes they might as well be.\n\n## Identify the error type\n\n![An example of a runtime error in BlockPy is shown](intro_errors_type_error.png)\n\nLet's imagine that we ran some code and encountered an error message.\nIn the bottom left of the error message, you can see the type of error.\nIn the example here, you can see that we have a `TypeError`.\nAfter the error type, there is usually some further description of the error.\n\n## Find the Line\n\n![The same error messages are shown from the previous slide, but this time the line number is circled instead.](intro_errors_line.png)\n\nIt can be tricky to read, but the error message should also identify WHERE the error occurred.\nThis is called the _traceback_, because it \"traces back\" through the code to show you where the error occurred.\nThe traceback shows you the line number and the actual line of code where the error occurred.\nOf course, sometimes the error is actually caused by code on a previous line instead of the line shown.\nYou will have to think very critically about whether the error message is correct.\n\n## Common Errors: NameError\n\n```python example-name-error\nstudent_grade = 10\n# Note the typo below!\nprint(studten_grade)\n```\n\nLet's look at a few common errors.\nFirst, the code below causes a `NameError`.\nA `NameError` comes up when you try to reference a variable that does not exist yet.\nSometimes, you misspelled the name of the variable.\nSometimes, you have not initialized the variable.\nSometimes, you initialized the variable, but you did so AFTER its first usage.\nIn this case, there is a typo in the name `student_grade`.\nTry running the code to see the error.\n\n## Common Errors: TypeError\n\n```python example-type-error\nprint(\"7\"+3)\n```\n\nAnother common error is the `TypeError`, like in the code shown here.\nA `TypeError` occurs when you use an operator incorrectly.\nFor example, adding together a string and a number is not allowed.\nWhen you read the error message that is produced, it will describe what went wrong.\nHere, it says that we attempted to concatenate (which means combine) a string and an integer.\n\n## Reminder: Type Rules\n\n* Cannot add integers to strings\n* Cannot multiply two strings\n* Can use equality and inequality on any types\n* Cannot use order comparison between strings and integers\n\nRemember that there are five basic types we have learned so far (integer, float, string, Boolean, and the special None type.) The various operators have their own special rules for whether an operation is valid on specific types.\nSometimes, these rules can be very surprising, like the following examples.\n\nYou can add integers to integers and strings to strings, but you _cannot_ add integers to strings and vice versa.\n\nYou can multiply integers and floats, and you can also multiply an integer by a string (it will repeat the string that many times.)\nHowever, you _cannot_ multiply two strings.\n\nYou can always use `==` and `!=` to test the equality/inequality of any two values, even if they are different types (although strings and integers will never be equal.)\n\nYou can only use the order comparison operators (`<`, `>`, `<=`, `>=`) to check the order of numerics (integer and floats) with other numerics, or strings with other strings. You _cannot_ mix strings and integers with the order operators.\n\nYou can test if one string is `in` another string, but you _cannot_ use the `in` operator with integers.\n\n## Common Errors: SyntaxError\n\n```python example-syntax-error\nname = \"Klaus von Wagglyschwantz\"\nage = 17\nis_good_dog = True\nprint(\"Klaus is a good dog?)\nprint(is_good_dog)\n```\n\nA `SyntaxError` means that you broke Python's rules of spelling, grammar, and punctuation.\nThere are many ways to break a program's syntax.\nUsually, Python is very good at suggesting where the error is.\nStill, sometimes it can be very tricky to track down a `SyntaxError`.\nYou usually want to look at the line where the error occurs and also the previous line of actual code.\n\nCan you spot the SyntaxError in the code shown?\nThe second string literal (`\"Klaus is a good dog?\"`) is missing its ending double quote! Often, a SyntaxError occurs because you drop a single character, forget to close a parentheses or string literal, or some other silly mistake.\n\n## Debugging Errors\n\n![The previously confused looking student wearing a Sherlock Holmes outfit, now confidently staring in confusion at the Error Computer.](intro_errors_sherlock_holmes.png)\n\nWe'll learn some more techniques to help you fix your broken problems later.\nFor now, think critically about the errors you receive.\nWhen you see one you don't understand, you should ask \"What does this error message mean?\" instead of just \"What is wrong with my program?\" Treat each error message as a mystery and yourself as a detective.\n\n## Summary\n\n- Errors are also known as exceptions.\n- When writing code, it is normal to encounter errors during development, but you do have to fix the errors (called \"debugging.\")\n- Python errors come in many different types, such as TypeError, NameError, and ValueError.\n- When you encounter an error, you should look at the type of error, the error message, and the location of the error according to the traceback.\n- Debugging requires a lot of critical thinking since the error message may not exactly describe the issue with your code.\n\n","ip_ranges":"","name":"1B8) Errors Reading","on_change":"","on_eval":"","on_run":"","owner_id":1,"owner_id__email":"acbart@udel.edu","points":0,"public":true,"reviewed":false,"sample_submissions":[],"settings":"{\n  \"header\": \"Errors\",\n  \"slides\": \"bakery_intro_errors.pdf\",\n  \"youtube\": {\n    \"Bart\": \"2ElcRMGPzI0\",\n    \"Amy\": \"nF52lYUxmPI\"\n  },\n  \"video\": {\n    \"Bart\": \"https://blockpy.cis.udel.edu/videos/bakery_intro_errors-Bart.mp4\",\n    \"Amy\": \"https://blockpy.cis.udel.edu/videos/bakery_intro_errors-Amy.mp4\"\n  },\n  \"summary\": \"In this lesson, you will learn how Python reports problems with your program, and how to respond to those errors.\",\n  \"small_layout\": true,\n  \"disable_tifa\": true\n}","starting_code":"","subordinate":true,"tags":[],"type":"reading","url":"bakery_intro_errors_read","version":8},"ip":"216.73.216.157","submission":{"_schema_version":3,"assignment_id":962,"assignment_version":8,"attempts":0,"code":"","correct":false,"course_id":37,"date_created":"2026-05-20T16:04:52.934125+00:00","date_due":"","date_graded":"","date_locked":"","date_modified":"2026-05-20T16:04:52.934125+00:00","date_started":"","date_submitted":"","endpoint":"","extra_files":"","feedback":"","grading_status":"NotReady","id":2037053,"score":0.0,"submission_status":"Started","time_limit":"","url":"submission_url-be8213d0-5512-4c37-b795-bcf1789e5033","user_id":2044700,"user_id__email":"","version":0},"success":true}
