{"assignment":{"_schema_version":2,"course_id":37,"date_created":"2022-06-28T19:00:00+00:00","date_modified":"2023-09-03T02:40:18.644875+00:00","extra_instructor_files":"","extra_starting_files":"","forked_id":null,"forked_version":null,"hidden":false,"id":970,"instructions":"## What Are Functions?\n\n* Functions: Reusable chunks of code\n\nFunctions are reusable chunks of code.\nOnce code is wrapped in a function, we can use it in other places.\nFirst, we'll learn how to use functions.\nLater, we'll learn how to make them.\n\n## Calling Functions\n\n* \"Use\" a function\n* \"Call\" a function\n* \"Invoke\" a function\n* \"Execute\" a function\n* \"Run\" a function\n\nWhen you want to \"use\" a function, we say that you \"call\" it.\nYou can also use the terms \"execute\" and \"run,\" although those will usually be for full programs.\nOne other word we sometimes use is \"invoke\", although that is less common.\n\n## Syntax\n\n```python\n# Function name followed by parentheses\nround(3.75)\n```\n\nThere are two essential parts to calling a function: The name of the function and then parentheses following the name.\n\n## Calling or Not\n\n![Two pictures, of a person talking about going to a store vs actually going to the store](functions_calling_parentheses.png)\n\nTo call a function, you MUST add parentheses.\nOtherwise, you are simply referring to the name of the function rather than executing it.\nThink of it as the difference between \"thinking about going to the store\" as opposed to \"actually physically going to the store.\" The parentheses are what make this a function call and not just the function name being referenced for no reason.\n\n## Functions vs. Programs\n\n![A diagram shows a box labelled \"input\" with an arrow pointing towards a bigger box labelled \"processing\", and another arrow pointing out that box pointing to \"output\". The bigger box is annotated as a \"program\". Inside the bigger box is a series of three sets of three smaller boxes, each labelled \"input -> processing -> output\". These boxes are labelled as functions. All together, there is a small black arrow tracing through all the boxes in order.](functions_calling_input_processing_output.png)\n\nA program and a function are similar, but not quite the same.\nThey both have the same \"Input-Process-Output\" pattern.\nHowever, functions are typically much smaller and meant to accomplish a _single specific task_.\nOften, a program will call many different functions in order to process all of its input into output.\n\n## Functions vs. Methods\n\n```python method-example\nmessage = \"MAKE THIS LOWERCASE\"\n\n# Call the `lower` method\nmessage = message.lower()\nprint(message)\n```\n\nMethods are a special kind of function.\nThey are attached strongly to a value.\nThe way we write a method call is slightly different, too, since it needs to incorporate that value.\nWhen you want to use a _method_, you need the name, parentheses, AND two more pieces: the calling value or variable and a period.\nIn later lessons, we'll learn more about this strange syntax.\nFor now, get comfortable with the difference between calling functions and methods.\n\n## Delegation of Work\n\n![On the left, a boss asks an employee to \"create a report on sales\". In the middle, the phrase \"time passes\" appears.  On the right, the employee has returned and says \"Here is the report, sir\"](functions_calling_magic_report.png)\n\nYou don't have to know how a function accomplishes its goal to use it.\nThink of it like a well-run office.\nWhen you ask a co-worker to complete some work, you don't care how it happens \u2014 just the inputs and outputs to their process.\nThis separation of concerns allows you to focus on pieces of a program without worrying about the whole thing.\n\n## Arguments\n\n```python arguments-example\n# 1 argument\nround(4.3)\n\n# 3 arguments\nprint(\"First\", \"Second\", \"Third\")\n\n# Zero arguments - prints a blank line\nprint()\n```\n\nOne of the most useful features of functions is _arguments_.\nArguments are values that are given to functions that affect the behavior of the function.\nArguments for a function are placed inside the parentheses, and each one is separated by a comma.\nWe say that these arguments are being _passed_ to the function.\nFunction calls do not always require arguments.\nThe last example above shows how the `print` function doesn't need to take any arguments; the function will still print, but only an empty line.\nThe number of arguments depends on the function and what you want to do with the function.\nSome functions take one argument all the time, some take multiple arguments sometimes, and everything in between.\n\n## Returning Values\n\n```python returned-values\n# call function, result is returned and assigned\nnew_value = round(3.9)\n\n# Can use print it, update it, etc.\nprint(new_value)\nnew_value += 1\nprint(new_value)\n```\n\nFunction calls return values, just like operations.\nFunctions can return any type of value: string, Boolean, integer, whatever.\nMentally, when a function is called, you can imagine the result replacing the entire function call.\nIn a way, this is like what happens when you do addition or subtraction.\n\n\n\n## Magic Function Box\n\n![A picture of a machine with two slots on top and one slot on the right side. Numbers are going into the slots on top and coming out of the slot on the right. The machine is labeled as \"Magic Function Box\", the slots coming in are labeled as \"arguments\", and the slot coming out is labeled as \"returns\".](functions_calling_magic_box.png)\n\nThink of a function as a magic box full of machinery.\nYou may not be able to see inside the box to know how it works, but you do not need to.\nArguments are the knobs and dials on the outside of the box that let you control its inner workings.\nReturned values are like a slot that dispenses the results of the function.\n\n## Summary\n\n- There are two essential parts to calling a function: the name of the function and parentheses.\n- Parentheses are absolutely essential to calling a function.\n- Usually, when you call a function, you also pass in arguments to the function by putting them between the parentheses, so that the function can manipulate the arguments.\n- Functions return a value when they are finished being evaluated, which is substituted in just like an operation.\n- Methods are a special kind of function where the first argument's value is placed BEFORE the name of the function along with a period.\n- Functions are essentially smaller versions of programs made for a single specific task.\n- Programs are usually composed of many function calls.\n- Functions can be treated like an opaque box that you cannot see inside of that transforms values for you; even if you do not know how that box works, you can still use the box to get things done.\n","ip_ranges":"","name":"2A1) Calling Functions 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\": \"Calling Functions\",\n  \"slides\": \"bakery_functions_calling.pdf\",\n  \"youtube\": {\n    \"Bart\": \"82IqXIziLfU\",\n    \"Amy\": \"RdaGz6sSktw\"\n  },\n  \"video\": {\n    \"Bart\": \"https://blockpy.cis.udel.edu/videos/bakery_functions_calling-Bart.mp4\",\n    \"Amy\": \"https://blockpy.cis.udel.edu/videos/bakery_functions_calling-Amy.mp4\"\n  },\n  \"summary\": \"In this lesson, you will learn about how to use functions. Functions are a fundamental element of programming that allow you to reuse code. Functions are a complex tool, so we will learn more about them in the next lesson. When you complete this one, you should feel free to continue directly onto the next one!\",\n  \"small_layout\": true\n}","starting_code":"","subordinate":true,"tags":[],"type":"reading","url":"bakery_functions_calling_read","version":9},"ip":"216.73.216.157","submission":{"_schema_version":3,"assignment_id":970,"assignment_version":9,"attempts":0,"code":"","correct":false,"course_id":37,"date_created":"2026-05-20T16:04:53.948481+00:00","date_due":"","date_graded":"","date_locked":"","date_modified":"2026-05-20T16:04:53.948481+00:00","date_started":"","date_submitted":"","endpoint":"","extra_files":"","feedback":"","grading_status":"NotReady","id":2037055,"score":0.0,"submission_status":"Started","time_limit":"","url":"submission_url-00142220-6d9d-44a5-aa3c-17e1178e57a4","user_id":2044700,"user_id__email":"","version":0},"success":true}
