Create, evaluate, or refine an educational lecture, learning activity, talk, or blog post
Generate curriculum and content like professional who specializes in high quality, engaging undergraduate education.
Complexity should generally increase through Bloom's as lecture progresses (remember -> understand -> apply -> analyze -> evaluate -> create)
Create a clear Teaching Goal and 2–3 measurable Learning Objectives
If generating markdown, save the teaching_goal string, learning_objectives list.
Use the following formatting for slide decks.
## title or ---. Use ## for titled slides and --- for untitled slides. Never use both for one break# title immediately followed by ## subtitle. Avoid the word "lecture"For lectures slides:
Always search for matching images and quotes that could be included using the following script:
python3 scripts/related_content.py "Guido van Rossum" "Triangle Area" "Variable"
Interleave up to four images and cited quotes only if appropriate matches are found.
---
teaching_goal: Students will understand the purpose and usage of variables and basic input/output in Python.
learning_objectives:
- Define and assign values to variables using descriptive names
- Collect and process user input using input() and type conversion functions
- Implement a simple program that calculates and displays a result based on user input
---
# Variables
## Named Containers
---
> One of the most powerful features of a programming language is the ability to manipulate variables.
>
> [PY4E](https://openlibrary.org/isbn/9781530051120)
## Definition
A [variable](<https://en.wikipedia.org/wiki/Variable_(high-level_programming)>) is a named container for a value
## Statements
- A [statement](<https://en.wikipedia.org/wiki/Statement_(computer_science)>) is a unit of code that the Python interpreter can execute
- Example: `print("Hello, world")`
## Assignment Statement
- Creates or rebinds a variable
- Gives the variable a value
```python
myvar = 42
```
## Usage
- Useful for organizing data flow
- Provide human-readable names for values
- Allow values to be reused
## Example
```python
>>> base = 5
>>> height = 6
>>> area = 0.5 * base * height
>>> area
15.0
```
---
> You shall love your neighbor as yourself.
>
> [Matthew 22:39 ESV](https://www.biblegateway.com/passage/?search=matthew%2022%3A39&version=ESV)
---
How can thoughtfully named variables help us demonstrate love for our neighbor?
## Variable Names
- Should document what the variable is used for
- May include letters and numbers
- Should be lowercase
- May not begin with a number
## Input Statement
- `input(prompt=None)`
- Accepts user input as an `str` (string)
- `prompt` will be shown to user if provided
- [Documentation for input](https://docs.python.org/3/library/functions.html#input)
## input Example
```python
user_msg = input("I'm an assistant. How may I help you?")
print("It sounds like you'd like help with the following:")
print(user_msg)
print("I'm not able to help with that.")
```
## int
- `int` converts strings to integers
## Examples
```python
>>> '12'
'12'
>>> int("12")
12
>>> int("Hello world!")
...ValueError...
>>> int("12.0")
...ValueError...
```
## Comments
- Can be inserted into code as notes for human readers
- Ignored by Python interpreter
- Begin with `#` symbol
---
{height=540px}
## Example Program
```python
base = int(input("Base: "))
height = int(input("Height: "))
area = 0.5 * base * height
print("Area of the triangle:")
print(area)
```
---
How could the readability of this program be improved?
## Exercise
Modify the previous example to compute the area of a rectangle.