{ "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", "