{"assignment":{"_schema_version":2,"course_id":37,"date_created":"2022-06-28T19:00:00+00:00","date_modified":"2023-08-26T13:57:59.700867+00:00","extra_instructor_files":"","extra_starting_files":"","forked_id":null,"forked_version":null,"hidden":false,"id":923,"instructions":"## Expressions\n\n```python example-expressions\n# Literal values are expressions\nprint(5)\nprint(10.0)\nprint(True)\nprint(\"Hello\")\n\n# Math operations are expressions\nprint(1 + 2)\nprint(4 - 5)\nprint(8 / 4)\n\n# Boolean operators are expressions\nprint(5 > 4)\nprint(False or not True)\nprint(1 < 2 and 4 > 5)\n\n# Expressions can be inside of expressions\nprint(1 + 5 > 3 / 2 and 4 < 7 * 2)\nprint((1 + 2) * 3 < 10)\n```\n\nAn _expression_ is any kind of combination of literal values, mathematical operators, comparison operators, and Boolean operators.\nAny value alone is an expression.\nAll operations are expressions.\nExpressions can even be made up of other expressions.\n\n## Evaluation\n\n* Run a program\n* Evaluate an expression\n\nWhen Python encounters an expression, the result of the expression must be \"evaluated.\" We have previously described how we \"run\" a program.\nThe word \"evaluate\" is similar but used for expressions.\nYou \"run\" a program and \"evaluate\" an expression.\nThe expression will always result in some value which Python can then use in some way.\n\n## Substitution Model\n\n```python not-shown-result\n199 + 1 + 300\n```\n\nWhen you look at the expression `199 + 1 + 300`, one way to mentally solve the problem is to substitute the `199 + 1` term for `200`.\nThen, you can do the easier addition of `200 + 300`.\nYour brain imagines `200` even though the value is not literally in the expression.\nWhen evaluating an expression, Python will do the same kind of substitution.\nIt does not show the intermediate results like the `200`, but Python still did that calculation along the way.\nInterestingly, by default, Python will not show the final result either.\nUnless you use the `print` function, the result will not appear on the console when you run the code shown.\nThe confusing part here, though, is that Python _will_ still compute the value.\nThe result is just \"thrown away!\"\n\n## Throwing Away Results\n\n```python shown-not-shown\n# This is not printed\n1 + 2\n\n# This is printed\nprint(1 + 9)\n\n# This causes an error!\n1 / 0\n\n# This cannot be reached\nprint(4 * 2)\n```\n\nPython will evaluate every expression, from the top of the program down to the bottom.\nEven if an expression is not printed, the result of the expression will be calculated.\nThe first `1 + 2` expression is evaluated and results in `3`.\nBut since that `3` is not printed or used in any way, the result is ignored and left behind.\nHowever, the `1+9` expression evaluates to `10`, which is then printed on the console.\nThings get interesting when we reach the third statement `1/0`.\nThat expression is invalid but still must be evaluated.\nWhen Python tries to do division by zero, the program will stop with an error message.\nThis prevents Python from reaching the second `print` statement or even evaluating `4 * 2`.\n\n## Seeing the Results\n\n![The console with an arrow pointing to the Evaluate button](intro_eval_console.png)\n\nWe have previously described how the `print` and `input` commands will write text to the console area.\nWe said that the _console_ was like an interactive chat window that you can use to communicate with the computer.\nThis is even more true now, thanks to the console's ability to evaluate expressions.\nIn BlockPy, for instance, you can click the `Evaluate` button to make a new box appear where you can write expressions.\nThose expressions will be evaluated and the result will be shown immediately.\nNo `print` statement is required when you use the Evaluate mode.\nMost programming environments have some kind of console, also known as a _shell_ or _terminal_, that lets you write and evaluate expressions.\nThey sometimes call this a _REPL_, which stands for \"Read-Evaluate-Print-Loop.\" The computer repeatedly reads input from the programmer, evaluates the expression, prints the result, and then loops (does it again).\nWhenever you find yourself needing a calculator, that the Evaluate button is right there to let you quickly do math or logic with Python.\n\n## Console Printing\n\n```python console-printing\n1 + 2\nprint(3 + 4)\n```\n\nSince the console automatically prints, you will not need to include print statements when using the Evaluate button.\nBut your regular Python programs will definitely still need to print when you want to see the results of the execution.\nTry running the following program.\nThen, click the Evaluate button and write and run each line of the program one at a time.\nCompare the output between evaluating code and running code, with and without a `print` statement.\nAnother small note to remember: the evaluate button is only available AFTER a program successfully runs. If there is an error,\nthe button will not appear.\n\n## Summary\n\n- The console is a place where you can write Python expressions and evaluate them. The result will automatically be printed even if you do not print explicitly.\n- When you run a program, all expressions are evaluated, even if their result is not printed (and will therefore not be visible to the user).\n- Python evaluates expressions one step at a time and substitutes the results at runtime. You cannot see these values when you look at the source code, but they were calculated.","ip_ranges":"","name":"1A8) Interactive Evaluation 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  \"small_layout\": true,\n  \"header\": \"Interactive Evaluation\",\n  \"slides\": \"bakery_intro_eval.pdf\",\n  \"youtube\": {\n    \"Bart\": \"jiOuQvLo_RU\",\n    \"Amy\": \"A7ouCYQ2iLY\"\n  },\n  \"video\": {\n    \"Bart\": \"https://blockpy.cis.udel.edu/videos/bakery_intro_eval-Bart.mp4\",\n    \"Amy\": \"https://blockpy.cis.udel.edu/videos/bakery_intro_eval-Amy.mp4\"\n  }\n}","starting_code":"","subordinate":false,"tags":[],"type":"reading","url":"bakery_intro_eval_read","version":9},"ip":"216.73.216.157","submission":{"_schema_version":3,"assignment_id":923,"assignment_version":9,"attempts":0,"code":"","correct":false,"course_id":37,"date_created":"2026-05-20T23:50:35.998137+00:00","date_due":"","date_graded":"","date_locked":"","date_modified":"2026-05-20T23:50:35.998137+00:00","date_started":"","date_submitted":"","endpoint":"","extra_files":"","feedback":"","grading_status":"NotReady","id":2037095,"score":0.0,"submission_status":"Started","time_limit":"","url":"submission_url-6961048a-8214-4626-ab0c-c721af82247a","user_id":2044772,"user_id__email":"","version":0},"success":true}
