{"assignment":{"_schema_version":2,"course_id":37,"date_created":"2022-06-28T19:00:00+00:00","date_modified":"2023-08-26T13:57:03.592569+00:00","extra_instructor_files":"","extra_starting_files":"","forked_id":null,"forked_version":null,"hidden":false,"id":917,"instructions":"## Computers Are Good at Math\n\n![A laptop thinking about 2+2](intro_math_laptop_math.png)\n\nIn some ways, computers are just large machines for doing math.\nComputers are very, very good at doing math.\nIn fact, modern computers can perform billions or even trillions of calculations per second.\nHowever, the math they do is extremely simplistic, the kind that you learned as a child.\nFortunately, programs can use these simple operations together to build more complicated operations.\n\n## Operators\n\n* `+`  Addition  \n* `-`  Subtraction  \n* `*`  Multiplication  \n* `/`  Division  \n* `//`  Integer Division\n* `**`  Exponentiation  \n* `%`  Modulo\n\nThere are seven basic mathematical operators in Python that we will review and that you will use in Python: Addition, Subtraction, Multiplication, Float Division, Integer Division, Exponentiation, and Modulo.\n\n## Operators and Operands\n\n* Operands: The values on either side of the operator.\n\nThe values to the left and right of the operator are called \"_operands._\" We will also sometimes casually call them \"arguments\" or \"inputs\" to the operation, but the correct word is \"operand.\"\n\n## Addition and Subtraction\n\n```python example-addition\n# Addition\nprint(1 + 1)\nprint(-10 + 10)\nprint(5.0 + 5)\n\n# Subtraction\nprint(5 - 8)\nprint(10 - 3.4)\n```\n\nThe `+` operator is used for addition, and the `-` operator is used for subtraction.\nNote that the `print` function is not required to do the math calculation; it is only required to see the result.\n\n## Multiplication and Exponentiation\n\n```python example-multiplication\n# Multiplication\nprint(4 * 2)\nprint(-5 * 5)\nprint(.5 * 10)\nprint(.5 * 4)\n\n# Exponents\nprint(2 ** 4)\nprint(10 ** .5)\n```\n\nOne asterisk (`*`) is used for multiplication.\nTwo asterisks (`**`) are used for exponents (also known as powers).\n\n## Division\n\n```python example-division\n# Float division\nprint(3 / 12)\nprint(1 / 1)\nprint(2.5 / 5)\n\n# Integer division\nprint(2.5 // .5)\nprint(2.5 // 5)\nprint(4 // 3)\n\n# Oops, error!\nprint(1 / 0)\n```\n\nThe forward slash (`/`) is used for float division.\nWhen you divide two integers with float division, you will ALWAYS get a floating-point number.\nI'll say that again: _Whenever_ _you do regular float division with a single slash, the result will always be a float!_ It does not matter if the result could be expressed as a whole number integer; Python will always make the result a float.\nTwo forward slashes (`//`) are used for integer division.\nIf both operands are integers, the result will be converted to an integer by truncating the result (removing the decimal).\nHowever, if either operand is a float, then the result will still be a float.\nKeep in mind, you cannot divide by `0`! This causes an error if you try running the code.\nThe operation is _syntactically_ valid, but _semantically_ incorrect.\n\n## Modulo\n\n```python example-modulo\nprint(16 % 12)\nprint(4 % 2)     # Even numbers produce 0\nprint(5 % 2)     # Odd numbers produce 1\nprint(6 % 2.1)\nprint(12.5 % .5)\n```\n\nYou may never have heard of the _Modulo_ operator, but programmers use it occasionally: Modulo calculates the remainder after division.\nModulo is sometimes called \"clock arithmetic\" because it makes it easy to figure out time.\nIf someone said, \"It is 16 o'clock\", you could do \"16 modulo 12\" and find out they meant \"4 pm\".\nHowever, modulo has many other uses, like figuring out if numbers are even or odd.\n\"(Any number) modulo two\" will help you figure out if the number is even or odd; if it is an odd number, the result will be `1`; if it is an even number, the result will be `0`.\n\n## Using the Operators\n\n```python example-chaining\nprint(2 + 3 + 4)\n```\n\nWhen you run a program with operators, Python will do the math and then replace the result.\nYou will not be able to see the computer do the math by looking at the code!\nThe result will seem to appear in the console immediately.\nHowever, the computer did not execute the code instantly, but instead had to first break down the operations into smaller steps.\nFirst, the computer will add `2` and `3`.\nThen the computer will add the resulting `5` to `4`.\nThe final result (`9`) is what is printed to the user without any of the intermediate results being shown.\n\n## Order of Operations\n\n* Please (Parentheses)  \n* Excuse (Exponents)  \n* My (Multiplication), Most (Modulo), Dear (Division)  \n* Aunt (Addition), Sally (Subtraction)\n\nWhen you use operators, there is an order of operations.\nWhenever there's a tie, the left-most operation happens first.\nNotice that you can always override any ordering by using parentheses.\nYou might already be familiar with this order, if not, here is a useful mnemonic.\n**PEMMDAS**: \"Please Excuse My Most Dear Aunt Sally.\"\nEach word of the mnemonic references the order of the operation.\nPlease (Parentheses), Excuse (Exponents), My (Multiplication), Most (Modulo), Dear (Division), Aunt (Addition), Sally (Subtraction).\nThe words shown on the same line have the same level of priority.\n## Floats and Integers\n\n```python example-float-int\n# Integers make integers\nprint(1 + 1)\n\n# Any floats make floats\nprint(1 + 1.0)\nprint(1.0 - 1)\n\n# Always integer\nprint(5.5 // .3)\n\n# Always float\nprint(6 / 3)\n```\n\nYou will recall that floats are decimal numbers and integers are whole numbers.\nWhen any operation involves any floats, the final result will always be a float \u2014 even if it could be expressed as a whole number.\nThe only exception to this rule is when you do division.\nRemember, _integer division with integers will produce an integer, but integer division with floats will produce floats_.\n\n## Summary\n\n- Python supports seven main math operators: addition (`+`), subtraction (`-`), multiplication (`*`), exponents (`**`), float division (`/`), integer division (`//`), and modulo (`%`).\n- These operators take in two operands each and substitute the result during execution.\n- Complex mathematical expressions can be nested together with parentheses, but the order of operations must be followed carefully. The mnemonic PEMMDAS (Please Excuse My Most Dear Aunt Sally) can be used to remember the order: Parentheses, Exponents, Modulo, Multiplication, Division, Addition, Subtraction.\n- Any math operation involving a float value will always result in a float, no matter what.","ip_ranges":"","name":"1A6) Math 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\": \"Math\",\n  \"slides\": \"bakery_intro_math.pdf\",\n  \"youtube\": {\n    \"Bart\": \"yMGucVnfnac\",\n    \"Amy\": \"FwWdtZ-4Hak\"\n  },\n  \"video\": {\n    \"Bart\": \"https://blockpy.cis.udel.edu/videos/bakery_intro_types-Bart.mp4\",\n    \"Amy\": \"https://blockpy.cis.udel.edu/videos/bakery_intro_types-Amy.mp4\"\n  },\n  \"summary\": \"In this lesson, you will learn about how to create arithmetic expressions. In other words, how you use math when programming.\",\n  \"small_layout\": true\n}","starting_code":"","subordinate":true,"tags":[],"type":"reading","url":"bakery_intro_math_read","version":8},"ip":"216.73.216.131","submission":{"_schema_version":3,"assignment_id":917,"assignment_version":8,"attempts":0,"code":"","correct":false,"course_id":37,"date_created":"2026-04-04T18:13:38.312794+00:00","date_due":"","date_graded":"","date_locked":"","date_modified":"2026-04-04T18:13:38.312794+00:00","date_started":"","date_submitted":"","endpoint":"","extra_files":"","feedback":"","grading_status":"NotReady","id":2000230,"score":0.0,"submission_status":"Started","time_limit":"","url":"submission_url-5faf2646-6813-4c26-b90e-bd2d10cd60ae","user_id":2021021,"user_id__email":"","version":0},"success":true}
