{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1>1. Print, Calculator, Variable Types, and Operators</h1>\n",
    "<h2>09/29/23</h2>\n",
    "\n",
    "<h2>1.0 Introduction to Jupyter Notebooks</h2>\n",
    "First, this is a Jupyter Notebook, which enables a combination of markdown cells (like this one) to provide description alongside actual code that can be run. If you want to change a markdown cell, simply double-click on the text, make any changes you want to make, and click \"Run\" (the little play button) <b>above</b> to execute. You can add HTML-style tags to markdown cells to add details such as formatting and links.\n",
    "\n",
    "There are also code cells, which can actually be executed, just like in a normal programming environment. Click on the below code cell and try clicking \"Run\" (or type Shift+Enter). You can also modify the text that's being printed to the screen and try running it again."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2>1.1 Basic Variables</h2>\n",
    "Python has <b>dynamic typing</b>, which means that variable types are set automatically based on the input. This is handy if you're coming from an environment like Fortran that requires you to specify each and every time what kind of variable you want to create!\n",
    "\n",
    "Here are some of the most important variable types (more on these in a bit):\n",
    "<ul>\n",
    "    <li>Integer (short and long)</li>\n",
    "    <li>Floating point (float)</li>\n",
    "    <li>Strings</li>\n",
    "    <li>Booleans</li>\n",
    "    <li>NoneType</li>\n",
    "    <li>Lists and tuples</li> (Tuesday's class)\n",
    "    <li>Dictionaries</li> (Tuesday's class)\n",
    "</ul>\n",
    "\n",
    "Arithmetic operators:\n",
    "<ul>\n",
    "    <li>+ is addition</li>\n",
    "    <li>- is subtraction</li>\n",
    "    <li>/ is division</li>\n",
    "    <li>* is multiplication</li>\n",
    "    <li>** is exponentiation</li>\n",
    "</ul>\n",
    "\n",
    "Comparison operators:\n",
    "<ul>\n",
    "    <li>> is greater than</li>\n",
    "    <li>< is less than</li>\n",
    "    <li>>= is greater than or equal to</li>\n",
    "    <li>&lt= is less than or equal to</li>\n",
    "    <li>!= is not equal to</li>\n",
    "    <li>== is equal to</li>\n",
    "</ul>\n",
    "\n",
    "<b>Important note:</b> Python is case-sensitive! \"A\" is not the same thing as \"a\"."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Code that is preceded with a hashtag will not be read by the computer.\n",
    "# These comments are intended for human readers of this code!\n",
    "# Commenting your code is essential to ensure that you and others\n",
    "# will be able to interpret it down the road!\n",
    "\n",
    "# Now, let's try playing with some numbers...\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that all of the above are examples of Python's <b>dynamic typing</b>: assigning a variable a floating point value (i.e., including a decimal point) results in that variable being a float, whereas assigning a variable an integer value (i.e., no decimal point) results in that variable being an integer.\n",
    "\n",
    "You can also convert from one to the other using the int() and float() commands!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Convert a from a float to an integer.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Convert c from an integer to a float.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that the conversion from float to int <b>loses information</b> along the way: Python merely truncates everything after the decimal point.\n",
    "\n",
    "On the other hand, the conversion from int to float is <b>essentially lossless</b>: the same information is maintained."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Now let's try some mathematical operators.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When applying mathematical operations, Python tries to keep as much information as possible! This means that an integer and a float interacting together will result in a float as an answer. Likewise, division of integers will give you a float by default (this is new in version 3 of Python).\n",
    "\n",
    "<b>Why is a*b not exactly -7.56?</b>\n",
    "\n",
    "Floats are not exact numbers! There will always be some degree of rounding errors associated with floating point numbers (because we don't have infinite storage to keep an infinite number of digits after the decimal). As a result, it's good practice when comparing floats not to look for equality, but instead to look for \"close enough\" - there are functions to do this that we will see later!\n",
    "\n",
    "You can also represent scientific notation in Python!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Let's represent 6 x 10^23 in Python!\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2>1.2 Strings</h2>\n",
    "\n",
    "Strings are the text variable type in Python: they're surrounded either by single or double quotes (it generally doesn't matter which, as long as you're consistent at the start and finish)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you want to combine two strings, you can do so easily with the \"+\" command."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# To add a space, simply throw another string in there.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# How about combining a string and a float?\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The <b>TypeError</b> you get in the above example explains the problem: a float cannot be combined in this way with a string. But what if we want to make this change? That's where the str() function comes in handy."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Let's try that again!\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Sometimes you want a new line within the same string. This can be accomplished with the \"escape character\", which in Python is a backslash: \\\\. \"\\n\" will start a new line!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Creating a multi-line string using the newline character.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you don't want to deal with newlines being created automatically, you can create a raw string!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# This will give you a nonsense result because \\n is being treated as a new line.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Instead, tell Python you're going to make a raw string by adding the letter 'r'.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2>1.3 Boolean Variables</h2>\n",
    "\n",
    "A Boolean variable can only have two values: <b>True</b> and <b>False</b> (and remember, capitalization counts!) These are the results of the logical tests mentioned earlier!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also combine conditions using <b>and</b> and <b>or</b>.\n",
    "\n",
    "<b>and</b>: Both statements must be <b>True</b> in order for the entire statement to be <b>True</b>.\n",
    "\n",
    "<b>or</b>: Either statement (or both) can be <b>True</b> in order for the entire statement to be <b>True</b>."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2>1.4 NoneType</h2>\n",
    "\n",
    "A NoneType variable can only have one value: <b>None</b> (and capitalization counts!). \n",
    "\n",
    "Why would we want this? Consider the scenario where you want to make sure there's no value already in a given variable (so, for example, if you're working with thousands of lines of code and the same variable types keep coming up). Setting that variable to None (via something like <b>a = None</b>) means you're guaranteed not to be messing around with any previous values by accident."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1>TAKE-HOME POINTS</h1>\n",
    "\n",
    "<ul>\n",
    "    <li>Python has a variety of data types, many of which we saw today!</li>\n",
    "    <li>An <b>integer</b> variable is a number with no decimal point.</li>\n",
    "    <li>A <b>floating point</b> variable is a number with a decimal point</li>\n",
    "    <li>A <b>string</b> variable is text.</li>\n",
    "    <li>A <b>Boolean</b> variable can take on the values <b>True</b> and <b>False</b>.</li>\n",
    "    <li>A <b>NoneType</b> variable can take on the value <b>None</b>.</li>\n",
    "    <li>Python uses dynamic typing, which means you don't need to define a variable's type when you first use that variable.</li>\n",
    "    <li>The type() command lets you see what type a given variable is. int(), float(), and str() can be used to convert to different variable types.</li>\n",
    "    <li>Combining a float and an integer results in a float.</li>\n",
    "    <li>Combining a string and an integer or float results in a TypeError.</li>\n",
    "    <li>Floats are often prone to rounding errors.</li>\n",
    "    <li><b>and</b> and <b>or</b> can be used to combine Boolean variables.</li>\n",
    "</ul>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
