{"assignment":{"_schema_version":2,"course_id":37,"date_created":"2022-06-28T19:00:00+00:00","date_modified":"2023-08-26T14:01:31.943676+00:00","extra_instructor_files":"","extra_starting_files":"","forked_id":null,"forked_version":null,"hidden":false,"id":926,"instructions":"## Purpose\n\n```python example-variables\ncakes_needed = 4\ncups_sugar = cakes_needed * 2\neggs = cakes_needed * 4\ncups_flour = cakes_needed * 3\ningredients = cups_sugar + eggs + cups_flour\nprint(\"You need\", ingredients, \"ingredients.\")\n```\n\nVariables let us store and load information.\nIn other words, we can \"read from\" and \"write to\" a variable with data.\nThis lets us use data later.\nIn the following example code, the variables are `cups_sugar`, `eggs`, and `cups_flour`.\n\n## Metaphor\n\n![Three separate visuals showing assignments made with labels. The first assignment of the value 64 to the variable age is next to a picture of the number 64 with a tag that says age attached. The second visual has two assignments of 16 to the variables cost and eggs, next to a picture of the number 16 with two tags that say eggs and cost. The third visual has the variable age being updated to 65, next to a picture of the age tag being moved from the number 64 to the number 65.](intro_variables_label_model.png)\n\nThink of a variable as a label that gets attached to a value.\nThat value could be a number, a string, or any type of data.\nAfter the label is attached, we can find out what its value is later.\nThe same value can have multiple labels attached.\nWe can also reattach the label to a different value.\n\n## Variables vs. Data\n\n```python printing-literals\n# Printing literal\nprint(14 * 7)\n\n# Write-and-read variable\nage = 14 * 7\nprint(age)\n```\n\nAnywhere that you use literal data, you can replace it with a variable.\nIn this example, we have extracted the mathematical expression to a variable.\nThis variable can then be used in subsequent lines.\n\n## Different from Math\n\n```python update-variable\nfootball_score = 0\nprint(football_score)\nfootball_score = 10\nprint(football_score)\nfootball_score = 27\nprint(football_score)\n```\n\nVariables in computing are very different from variables in math.\nIn math, a variable is an unknown that we are solving for.\n_In computing, we always know the value of a variable_ and we are able to manipulate the value if we want to.\nA variable changes over time \u2014 but only according to instructions that the programmer has written.\nThat means, unlike in math, when you're programming, you are allowed to change the value of a variable.\n\n#### Names\n\n```python mystery-temperature\n# Is this temperature in celsius? Or fahrenheit? Who knows!\ntemperature = 20\n\nprint(\"The temperature is\", temperature)\n```\n\nVariables are defined by their name.\nNames are crucial in programming and choosing them is an art.\nNames are best when they are accurate, meaningful, and concise.\nWe use good variable names to communicate clearly \u2014 not just with other programmers, but with ourselves when we need to figure out code that we have written.\nOf course, computers do not understand variable names; their meaning only matters to humans.\n\n#### Naming Rules\n\n- Names can only have letters, numbers, and underscores.\n- Names must begin with a letter or underscore.\n\nThere are two rules for naming variables in Python.\nFirst, names can only have letters, numbers, and underscores (`_`).\nSecond, names must begin with a letter or underscore.\nYou can use underscores to serve as spaces between words, since spaces are not allowed in variable names.\n\n## Naming Suggestions\n\n- **Clear**: Understandable without explanation\n- **Concise**: Not too short, not too long\n- **Correct**: Name accurately reflects the value\n- **Consistent**: Same style throughout the program\n- **Conventional**: Matches the style of most other programmers\n\nAlthough there are only two hard rules, we have five suggestions for good variable names.\nYou might find it helpful to remember them as the Five Cs.\n\nFirst, variable names should be **clear**.\nSomeone looking at the variable name should understand its purpose without needing additional explanations.\n\nSecond, the name should be **concise**, meaning neither too long nor too short.\nA name like `temperature_in_degrees_fahrenheit` is very clear but very long and inconvenient to type.\nThe name `t` is very short but totally unclear.\nBalancing clarity with conciseness is important.\nA clear and concise name might be `temperature` or even `fahrenheit_temperature`.\n\nThird, the name should be **correct**.\nAlthough this may sound obvious, far too often programmers will use a variable that does not accurately describe the data it holds \u2014 and refuse to fix it! This makes debugging the code much more difficult.\n\nThe last two suggestions are that variable names should be **consistent** and **conventional**.\nBeing consistent means having the same style throughout the program, while conventional means the same style as other programmers.\nWhen we say style, we mean like using certain abbreviations the same way throughout a program (for example, `temp` instead of `temperature`), or using underscores consistently instead of spaces (for example, some other programming languages would write `footballScore` instead of `football_score`).\nThere are many other kinds of stylistic choices, but we'll learn about them later.\n\n## Lazy Naming\n\n```python lazy-naming\nx = 147\nk = x * 2 + 4 - x\nprint(k)\n```\n\nMany novice programmers don't understand the value of good variable names.\nThey are eager and excited to write programs, willing to cut corners in their haste.\nSometimes, this means they will choose variable names like `x` or `k`.\nWhat do those variable names mean? Who knows?\nCertainly not anyone coming to read the code later!\nDon't be lazy when picking variable names.\nYes, having to do more thinking while coding is unpleasant, but sometimes we have to do hard things.\n\n## Summary\n\n- Variables are used to store values in a program for future use.\n- Programming variables are a different concept from math variables, since we always know a variable's value (although that value changes over the course of a program's execution.)\n- Variables have specific naming rules in Python:\n  - Names must start with a letter or underscore.\n  - Names must only contain letters, underscores, and digits.\n- Choosing good variable names is really important, so you should make the names:\n  - Correct: Make sure the name is accurate to the purpose of the variable and not misleading.\n  - Clear: Make sure the name is understandable without further explanation.\n  - Concise: Make sure the name is neither too long nor too short.\n  - Consistent: Make sure that all variable names within a program are written in the same style\n  - Conventional: Make sure that variable names across programs generally follow the same patterns that other programmers use.\n- Bad variable names make code harder to read, debug, and share.\n","ip_ranges":"","name":"1B1) Variables 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\": \"Variables\",\n  \"slides\": \"bakery_intro_variables.pdf\",\n  \"youtube\": {\n    \"Bart\": \"jrY2lmX2FLw\",\n    \"Amy\": \"eyxDCNwdNyk\"\n  },\n  \"video\": {\n    \"Bart\": \"https://blockpy.cis.udel.edu/videos/bakery_intro_variables-Bart.mp4\",\n    \"Amy\": \"https://blockpy.cis.udel.edu/videos/bakery_intro_variables-Amy.mp4\"\n  },\n  \"summary\": \"In this lesson, you will learn about how to create variables by using assignment statements, and then read and use those variables in your programs.\",\n  \"small_layout\": true\n}","starting_code":"","subordinate":true,"tags":[],"type":"reading","url":"bakery_intro_variables_read","version":9},"ip":"216.73.216.157","submission":{"_schema_version":3,"assignment_id":926,"assignment_version":9,"attempts":0,"code":"","correct":false,"course_id":37,"date_created":"2026-05-20T14:01:55.259232+00:00","date_due":"","date_graded":"","date_locked":"","date_modified":"2026-05-20T14:01:55.259232+00:00","date_started":"","date_submitted":"","endpoint":"","extra_files":"","feedback":"","grading_status":"NotReady","id":2036932,"score":0.0,"submission_status":"Started","time_limit":"","url":"submission_url-e75ac508-fec4-4c70-955d-43c5657780c5","user_id":2044668,"user_id__email":"","version":0},"success":true}
