{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Collegeboard APCSP 3.1.2 lesson\n", "> title is self-explanatory\n", "- toc: true\n", "- badges: true \n", "- comments: true \n", "- title: 3.1.2 lesson" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Learning objective for 3.1.2:\n", "Determine the value of a variable as a result of an assignment\n", "- done through looking at how we can use the assignment operator\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Note:\n", "Collegeboard uses <-- as the assignment operator\n", "- The assignment operator looks different for different types of coding languages\n", "A variable will take the most recent value assigned\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How do you even store a value inside a variable?\n", "\n", "Let's use python for our example:\n", " - In python, the assignment operator is the equal sign (=)\n", " - In order to store a value inside a variable, we must:\n", " - Give the variable a name\n", " - place the assignment operator \n", " - input the variable value\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "\n", "# Imagine you just played a video game and you have a highscore of 100. How do you store that value (integer)?\n", "highscore = 100\n", "\n", "# How do you store a number like 3.72?\n", "money = 3.72\n", "\n", "# What about storing your username (string)?\n", "username = \"name\"\n", "\n", "# What if it is raining outside and you want to store that fact (boolean)?\n", "is_raining = True\n", "\n", "# What about a list of groceries? \n", "groceries = [\"eggs\", \"flour\", \"bread\", \"milk\"]\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Let's look at an example\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "javascript" } }, "outputs": [], "source": [ "x = 10\n", "y = 20\n", "z = 30\n", "x = y\n", "z = x\n", "\n", "// what do you think z will be?\n", "\n", "print(z)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Let's get a little more practical here\n", "Imagine that you are making a calendar and have just finished the html code that is needed:\n", "- You now want to be able to switch between the months of the year by using the \"next\" or \"prev\" buttons\n", " - you will need to take the html elements and use them to your advantage\n", " - but how?" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "html" } }, "outputs": [], "source": [ "\n", "
\n", "
\n", "
\n", " \n", " \n", "
\n", "
\n", "
\n", "\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Recap:\n", "- We learned what is a assignment operator\n", "- We learned how to use the assignment operator\n", "- We learned how to store a value inside a variable using the assignment operator\n", "- We experimented with a few examples " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Hacks: \n", "Answer these:\n", "- In your **own** words, briefly explain by writing down what an assignment operator is\n", "- In Collegeboard pseudocode, what symbol is used to assign values to variables?\n", "- A variable, x, is initially given a value of 15. Later on, the value for x is changed to 22. If you print x, would the command display 15 or 22?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Hacks:\n", "Copy the all the html code into a markdown file and run your local server. You will then see a decimal to binary converter near the html code. The problem is that it is not converting the decimal to binary. This is because the variables are not defined properly and it is your job to use the information learned today to fix the converter. **Don't change the css**\n", "\n", "# Bonus (optional):\n", "There's more than one way to define the variable. List two ways to do it." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "html" } }, "outputs": [], "source": [ "\n", "
\n", "

Decimal to Binary converter

\n", "
\n", "
\n", " \n", " \n", " \n", " \n", " \n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.8.10 64-bit", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1" } } }, "nbformat": 4, "nbformat_minor": 2 }