{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3ba34554",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Expressions\n",
    "#### CS 65: Introduction to Computer Science I"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ea1529f9",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Expressions\n",
    "\n",
    "__expression:__ something _evaluated_ by the Python interpreter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2a35c582",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total field trip lunches: 52\n"
     ]
    }
   ],
   "source": [
    "num_students = 42\n",
    "num_adults = 10 \n",
    "total_field_trip_lunches = num_students + num_adults\n",
    "print(\"Total field trip lunches:\",total_field_trip_lunches)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bc233213",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "`num_students + num_adults` is _evaluated_ - results in an answer, so it is an expression\n",
    "\n",
    "expressions include __operators__, like `+`, and __operands__ like `num_students` and `num_adults`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "902447c5",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Arithmetic Operators\n",
    "\n",
    "Python supports all of the arithmetic operators you know and love:\n",
    "\n",
    "* `( )` parentheses\n",
    "* `**` exponents\n",
    "* `*` multiplication\n",
    "* `/` division\n",
    "* `+` addition\n",
    "* `-` subtraction\n",
    "\n",
    "PEMDAS order of operations\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c0d432cd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9.0"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "6 / 2*(1+2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c7a2771e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2**4 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af781355",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Keeping it simple\n",
    "\n",
    "Just because you _can_ write really complex expressions in Python doesn't mean you _should_."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5b7a2785",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Vacation budget: 3615.275\n"
     ]
    }
   ],
   "source": [
    "vacation_budget = (2.70 * 1224/32) + ((8-1) * 96) + (8 * ((40*4)+100)) + (4 * 190)\n",
    "print(\"Vacation budget:\",vacation_budget)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d939759a",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Vacation budget: 3615.275\n"
     ]
    }
   ],
   "source": [
    "avg_gas_estimate = 2.70\n",
    "round_trip_miles_to_memphis = 1224\n",
    "vehicle_mpg = 32\n",
    "gas_cost = avg_gas_estimate * (round_trip_miles_to_memphis/vehicle_mpg)\n",
    "\n",
    "vacation_days = 8\n",
    "\n",
    "hotel_nights = vacation_days-1\n",
    "hotel_per_night_cost = 96\n",
    "lodging_cost = hotel_nights * hotel_per_night_cost\n",
    "\n",
    "food_per_person_per_day = 40\n",
    "num_people = 4\n",
    "total_food_per_day = food_per_person_per_day*num_people\n",
    "souvenirs_and_incidentals_per_day = 100\n",
    "food_and_incidental_cost = vacation_days*(total_food_per_day+souvenirs_and_incidentals_per_day)\n",
    "\n",
    "graceland_ticket_cost = 190\n",
    "graceland_cost = num_people * graceland_ticket_cost\n",
    "\n",
    "vacation_budget = gas_cost + lodging_cost + food_and_incidental_cost + graceland_cost\n",
    "print(\"Vacation budget:\",vacation_budget)"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Slideshow",
  "kernelspec": {
   "display_name": "Python 3",
   "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.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
