|
|
<!doctype html>
|
|
|
<html lang="en">
|
|
|
<head>
|
|
|
<meta charset="utf-8">
|
|
|
|
|
|
<title></title>
|
|
|
|
|
|
<meta name="description" content="">
|
|
|
|
|
|
|
|
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
|
|
|
|
<!-- For syntax highlighting -->
|
|
|
<link rel="stylesheet" href="../../../../lib/css/zenburn.css">
|
|
|
<link rel="stylesheet" href="../../../../lib/css/prism.css">
|
|
|
|
|
|
<link rel="stylesheet" href="../../../../css/reveal.css">
|
|
|
<link rel="stylesheet" href="../../../../css/theme/ga-title.css" id="theme">
|
|
|
|
|
|
<!--[if lt IE 9]>
|
|
|
<script src="lib/js/html5shiv.js"></script>
|
|
|
<![endif]-->
|
|
|
|
|
|
<link rel="stylesheet" type="text/css" href="https://s3.amazonaws.com/python-ga/proxima-nova/fonts.css" />
|
|
|
|
|
|
</head>
|
|
|
|
|
|
<body class="language-javascript">
|
|
|
|
|
|
<div class="reveal">
|
|
|
|
|
|
<!-- Any section element inside of this container is displayed as a slide -->
|
|
|
<div class="slides">
|
|
|
|
|
|
|
|
|
<!--
|
|
|
title: Intermediate Variables
|
|
|
type: lesson
|
|
|
duration: "00:30"
|
|
|
creator: Brandi Butler
|
|
|
-->
|
|
|
<section id="section" class="level2 separator">
|
|
|
<h2><img src="https://s3.amazonaws.com/python-ga/images/GA_Cog_Medium_White_RGB.png" /></h2>
|
|
|
<h1>
|
|
|
Unit 3 Lab: Intermediate Variables
|
|
|
</h1>
|
|
|
<!--
|
|
|
|
|
|
## Overview
|
|
|
In order, this lesson will teach students about floating point numbers, floor division, implicit and explicit type conversion, escape characters, and string formatting. There is a short exercise near the end.
|
|
|
|
|
|
## Learning Objectives
|
|
|
In this lesson, students will:
|
|
|
|
|
|
* Create and floor floats.
|
|
|
* Use special string characters.
|
|
|
* Format strings.
|
|
|
|
|
|
## Duration
|
|
|
30 minutes
|
|
|
|
|
|
## Suggested Agenda
|
|
|
|
|
|
| Time | Activity |
|
|
|
| --- | --- |
|
|
|
| 0:00 - 0:03 | Welcome |
|
|
|
| 0:04 - 0:15 | Floats |
|
|
|
| 0:16 - 0:22 | Advanced Strings |
|
|
|
| 0:23 - 0:27 | String Formatting |
|
|
|
| 0:28 - 0:30 | Summary |
|
|
|
|
|
|
|
|
|
## In Class: Materials
|
|
|
- Projector
|
|
|
- Internet connection
|
|
|
- Python3
|
|
|
-->
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="lesson-objectives" class="level2">
|
|
|
<h2>Lesson Objectives</h2>
|
|
|
<p><em>After this lesson, you will be able to…</em></p>
|
|
|
<ul>
|
|
|
<li>Create and floor floats.</li>
|
|
|
<li>Use special string characters.</li>
|
|
|
<li>Format strings.</li>
|
|
|
</ul>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="introducing-floats" class="level2">
|
|
|
<h2>Introducing: Floats</h2>
|
|
|
<p>Did you notice that until now, we’ve only used whole numbers? Whole numbers are integers or, in programming terms, <code>int</code>.</p>
|
|
|
<p>Where are all the decimal points?</p>
|
|
|
<p>3.3, 1.1, and 2.2 are all <strong>floats</strong>.</p>
|
|
|
<ul>
|
|
|
<li>Short for “floating point value”</li>
|
|
|
<li>A number with a decimal point. Even 2.0 is a float - it has the decimal!</li>
|
|
|
<li>Just another numerical variable!</li>
|
|
|
</ul>
|
|
|
<div class="sourceCode" id="cb1"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb1-1" data-line-number="1">an_int <span class="op">=</span> <span class="dv">3</span> <span class="co"># Int!</span></a>
|
|
|
<a class="sourceLine" id="cb1-2" data-line-number="2">a_float <span class="op">=</span> <span class="fl">3.0</span> <span class="co"># Float!</span></a>
|
|
|
<a class="sourceLine" id="cb1-3" data-line-number="3">x <span class="op">=</span> <span class="fl">2.5</span> <span class="co"># Float!</span></a>
|
|
|
<a class="sourceLine" id="cb1-4" data-line-number="4">z <span class="op">=</span> <span class="fl">3.5</span> <span class="op">+</span> <span class="fl">2.5</span> <span class="co"># Adding floats - normal math.</span></a>
|
|
|
<a class="sourceLine" id="cb1-5" data-line-number="5">y <span class="op">=</span> x <span class="op">+</span> z</a>
|
|
|
<a class="sourceLine" id="cb1-6" data-line-number="6"><span class="bu">print</span>(y) <span class="co"># Prints 8.5.</span></a>
|
|
|
<a class="sourceLine" id="cb1-7" data-line-number="7"><span class="bu">sum</span> <span class="op">=</span> an_int <span class="op">+</span> a_float <span class="co"># What if we add an int and a float?</span></a>
|
|
|
<a class="sourceLine" id="cb1-8" data-line-number="8"><span class="bu">print</span>(<span class="bu">sum</span>) <span class="co"># Prints 6.0. Adding an int to a float will still make a float!</span></a></code></pre></div>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>Point out that adding anything to a float makes a float.</li>
|
|
|
</ul>
|
|
|
<p><strong>Talking Points</strong>:</p>
|
|
|
<ul>
|
|
|
<li>“Float is short for floating point real value, which in layman’s terms is simply a number with a decimal point.”</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="int-int-float" class="level2">
|
|
|
<h2>Int / Int == Float ?!</h2>
|
|
|
<p>A quotient is not necessarily a whole number! * <code>5 / 2 == 2.5</code> * <code>1 / 3 == 1.333...</code></p>
|
|
|
<p>Therefore, quotients are always floats - even when they look like ints. Python doesn’t distinguish!</p>
|
|
|
<ul>
|
|
|
<li><code>6 / 2 == 3.0</code></li>
|
|
|
<li><code>8 / 4 == 2.0</code></li>
|
|
|
</ul>
|
|
|
<p><strong>Protip:</strong> This is called <strong>implicit type conversion</strong> - Python changed our numbers from ints to floats automatically.</p>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>Throughout this and each following slide, allow time for discussion. It’s easy to breeze through this, but it’s a lot to cover.</li>
|
|
|
</ul>
|
|
|
<p><strong>Talking Points</strong>:</p>
|
|
|
<ul>
|
|
|
<li>“I started with two integers, how did I get a float? Well, if you think about it, it does make sense. You aren’t guaranteed that a quotient will be a whole number, even if you start out with two whole numbers. For example, 5 divided by 2 is 2.5, which is a float!”</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="explicit-type-conversion" class="level2">
|
|
|
<h2>Explicit Type Conversion</h2>
|
|
|
<p><code>6 / 2 == 3.0</code>: A float. What if you just want the int <code>3</code>? (Pretty soon, having the right type will be important!). We need <strong>explicit type conversion.</strong></p>
|
|
|
<ul>
|
|
|
<li><code>int()</code> converts something to an integer.</li>
|
|
|
<li><code>float()</code> converts to a float.</li>
|
|
|
<li><code>str()</code> converts to a string</li>
|
|
|
</ul>
|
|
|
<iframe height="400px" width="100%" src="https://repl.it/@SuperTernary/python-programming-type-conversion?lite=true" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals">
|
|
|
</iframe>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Talking Points</strong>: - “Explicit type conversion is basically like saying directly to Python, <code>I want this float to be an integer!</code>”</p>
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>This is a repl.it so it’s easy to demo to students how this works. This isn’t an exercise - don’t spend long on the slide. After running through what’s there, add at the bottom converting strings.</li>
|
|
|
</ul>
|
|
|
<p><strong>Repl.it Note</strong>: The replit has</p>
|
|
|
<div class="sourceCode" id="cb2"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb2-1" data-line-number="1">x <span class="op">=</span> <span class="dv">2</span></a>
|
|
|
<a class="sourceLine" id="cb2-2" data-line-number="2">y <span class="op">=</span> <span class="fl">3.5</span></a>
|
|
|
<a class="sourceLine" id="cb2-3" data-line-number="3">z <span class="op">=</span> <span class="st">"10"</span></a>
|
|
|
<a class="sourceLine" id="cb2-4" data-line-number="4"></a>
|
|
|
<a class="sourceLine" id="cb2-5" data-line-number="5"><span class="bu">print</span>(<span class="st">"Converting to integers"</span>)</a>
|
|
|
<a class="sourceLine" id="cb2-6" data-line-number="6"><span class="bu">print</span>(x, <span class="st">"to integer ->"</span>, <span class="bu">int</span>(x))</a>
|
|
|
<a class="sourceLine" id="cb2-7" data-line-number="7"><span class="bu">print</span>(y, <span class="st">"to integer ->"</span>, <span class="bu">int</span>(y))</a>
|
|
|
<a class="sourceLine" id="cb2-8" data-line-number="8"><span class="bu">print</span>(z, <span class="st">"to integer ->"</span>, <span class="bu">int</span>(z))</a>
|
|
|
<a class="sourceLine" id="cb2-9" data-line-number="9"><span class="bu">print</span>()</a>
|
|
|
<a class="sourceLine" id="cb2-10" data-line-number="10"></a>
|
|
|
<a class="sourceLine" id="cb2-11" data-line-number="11"><span class="bu">print</span>(<span class="st">"Converting to floats"</span>)</a>
|
|
|
<a class="sourceLine" id="cb2-12" data-line-number="12"><span class="bu">print</span>(x, <span class="st">"to float ->"</span>, <span class="bu">float</span>(x))</a>
|
|
|
<a class="sourceLine" id="cb2-13" data-line-number="13"><span class="bu">print</span>(y, <span class="st">"to float ->"</span>, <span class="bu">float</span>(y))</a>
|
|
|
<a class="sourceLine" id="cb2-14" data-line-number="14"><span class="bu">print</span>(z, <span class="st">"to float ->"</span>, <span class="bu">float</span>(z))</a></code></pre></div>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="we-do-lets-practice" class="level2">
|
|
|
<h2>We Do: Let’s Practice</h2>
|
|
|
<p>Let’s try:</p>
|
|
|
<ul>
|
|
|
<li>Declare two variables, <code>x</code> and <code>y</code>, and assign each an <code>int</code> value.</li>
|
|
|
<li>Declare a variable <code>z</code> and assign a <code>float</code> value.</li>
|
|
|
<li>Declare a variable <code>result</code>, which stores <code>x + y</code>. What type is <code>result</code>? Let’s convert it to other types.</li>
|
|
|
<li>Is this behavior the same for other operators <code>-</code>, <code>*</code>, <code>/</code>, or <code>**</code>? What about using <code>x</code> and <code>z</code>?</li>
|
|
|
</ul>
|
|
|
<iframe height="400px" width="100%" src="https://repl.it/@SuperTernary/Empty-Replit?lite=true" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals">
|
|
|
</iframe>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>We can run through each operator pretty quickly here, as this is expected behavior.</li>
|
|
|
<li>Walk through the exercise with them to make sure everyone has noticed that division produces a float out of two integers and can do the type conversion.</li>
|
|
|
</ul>
|
|
|
<p><strong>Talking Points</strong>:</p>
|
|
|
<ul>
|
|
|
<li>“Luckily most of the time, floats behave the way you’d expect.”</li>
|
|
|
<li>Afterward “You can combine floats and ints with mathematical operators, and the resulting type will be a float as well.”</li>
|
|
|
</ul>
|
|
|
<p><strong>Repl.it Note:</strong></p>
|
|
|
<ul>
|
|
|
<li>It’s empty.</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="quick-review-floats" class="level2">
|
|
|
<h2>Quick Review: Floats</h2>
|
|
|
<p>In programming:</p>
|
|
|
<ul>
|
|
|
<li>An <em>int</em> is a whole number: <code>1</code>, <code>0</code>, <code>-5</code>.</li>
|
|
|
<li>A <em>float</em> is a number with a decimal point: <code>1.6</code>, <code>-28.2</code>, <code>0.0</code>.</li>
|
|
|
<li>Doing any math with a float results in a float: <code>6 + 3.0 = 9.0</code>.</li>
|
|
|
<li>Dividing integers results in a float: <code>4 / 2 = 2.0</code></li>
|
|
|
</ul>
|
|
|
<p>You can use <em>explicit type conversion</em> to turn one variable type into another:</p>
|
|
|
<ul>
|
|
|
<li><code>int()</code> converts to an integer: <code>int(6.0) # 6</code></li>
|
|
|
<li><code>float()</code> converts to a float: <code>float(6) # 6.0</code></li>
|
|
|
<li><code>str()</code> converts to a string: <code>str(6) # "6"</code></li>
|
|
|
</ul>
|
|
|
<p><strong>Up next:</strong> Floor Division.</p>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>Do a quick check for understanding.</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="finding-the-midpoint" class="level2">
|
|
|
<h2>Finding the Midpoint</h2>
|
|
|
<p>One intermediate variable down! Let’s move on past floats.</p>
|
|
|
<p>What if we want to find the middle index of a list?</p>
|
|
|
<div class="sourceCode" id="cb3"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb3-1" data-line-number="1"><span class="co"># An odd numbered list (length of 5)</span></a>
|
|
|
<a class="sourceLine" id="cb3-2" data-line-number="2">characters <span class="op">=</span> [<span class="st">"Green Arrow"</span>, <span class="st">"Super Girl"</span>, <span class="st">"The Flash"</span>, <span class="st">"Wonder Woman"</span>, <span class="st">"Batman"</span>]</a>
|
|
|
<a class="sourceLine" id="cb3-3" data-line-number="3"></a>
|
|
|
<a class="sourceLine" id="cb3-4" data-line-number="4">index <span class="op">=</span> <span class="bu">len</span>(characters) <span class="op">/</span> <span class="dv">2</span> <span class="co"># Index is 2.5</span></a>
|
|
|
<a class="sourceLine" id="cb3-5" data-line-number="5"></a>
|
|
|
<a class="sourceLine" id="cb3-6" data-line-number="6"><span class="bu">print</span>(characters[index]) <span class="co"># There's no element 2.5!</span></a></code></pre></div>
|
|
|
<p>We want <code>2</code>. Any ideas? This is a very common use case - there must be a way!</p>
|
|
|
<p><strong>Protip:</strong> Remember, indexes start at 0!</p>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>Stress that this has nothing to do with floats. The lesson presentation is on a whole slew of intermediate variables. Now that we understand floats, we’re moving on to the next sub-topic.</li>
|
|
|
</ul>
|
|
|
<p><strong>Talking Points</strong>:</p>
|
|
|
<ul>
|
|
|
<li>“Sometimes we want to divide and get the nearest whole number. A common scenario for this is when you want to get the middle of a list. You can access the list with an index which must be an integer.”</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="introducing-floor-division" class="level2">
|
|
|
<h2>Introducing Floor Division</h2>
|
|
|
<p>Python has a shortcut.</p>
|
|
|
<p><strong>Floor division</strong> (a.k.a. integer division):</p>
|
|
|
<ul>
|
|
|
<li>We use <code>//</code> instead of just <code>/</code>.</li>
|
|
|
<li>Does normal division, then drops the decimal and returns an int.</li>
|
|
|
<li>Think of the floor - it’s beneath you. We floor by rounding <strong>down</strong>. The decimal is chopped! <code>2.8</code> will become <code>2</code>, not <code>3</code>.</li>
|
|
|
</ul>
|
|
|
<div class="sourceCode" id="cb4"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="co"># Gives 2.5</span></a>
|
|
|
<a class="sourceLine" id="cb4-2" data-line-number="2">float_index <span class="op">=</span> <span class="dv">5</span> <span class="op">/</span> <span class="dv">2</span></a>
|
|
|
<a class="sourceLine" id="cb4-3" data-line-number="3"></a>
|
|
|
<a class="sourceLine" id="cb4-4" data-line-number="4"><span class="co"># Gives 2!</span></a>
|
|
|
<a class="sourceLine" id="cb4-5" data-line-number="5">int_index <span class="op">=</span> <span class="dv">5</span> <span class="op">//</span> <span class="dv">2</span></a></code></pre></div>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Talking Points</strong>:</p>
|
|
|
<ul>
|
|
|
<li>“You may hear the terms <code>integer division</code> and <code>floor division</code> used interchangeably”</li>
|
|
|
<li>“If you recall the terms floor and ceiling from math class, you’ll understand that floor just means that the decimal is removed. Floor division is NOT the same as rounding to the nearest whole number! It literally just cuts off the decimal point!”</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="you-do-using-floor-division" class="level2">
|
|
|
<h2>You Do: Using Floor Division</h2>
|
|
|
<p>Correct the code by using floor division:</p>
|
|
|
<iframe height="400px" width="100%" src="https://repl.it/@SuperTernary/python-programming-floor-division?lite=true" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals">
|
|
|
</iframe>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>Give them just a couple minutes to do this, then show the answer.</li>
|
|
|
</ul>
|
|
|
<p><strong>Talking Points</strong>:</p>
|
|
|
<ul>
|
|
|
<li>“Let’s take a minute or two to correct our midpoint code from earlier”</li>
|
|
|
</ul>
|
|
|
<p><strong>Repl.it Note:</strong> This replit has:</p>
|
|
|
<div class="sourceCode" id="cb5"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb5-1" data-line-number="1"><span class="co"># Your job: Add multiplication (product) and division (quotient)</span></a>
|
|
|
<a class="sourceLine" id="cb5-2" data-line-number="2"><span class="co"># to the addition and subtraction that have already been done.</span></a>
|
|
|
<a class="sourceLine" id="cb5-3" data-line-number="3"><span class="co"># Observe: What is the result's type for each operation?</span></a>
|
|
|
<a class="sourceLine" id="cb5-4" data-line-number="4"></a>
|
|
|
<a class="sourceLine" id="cb5-5" data-line-number="5"><span class="co"># Start with two integers</span></a>
|
|
|
<a class="sourceLine" id="cb5-6" data-line-number="6">x <span class="op">=</span> <span class="dv">6</span></a>
|
|
|
<a class="sourceLine" id="cb5-7" data-line-number="7">y <span class="op">=</span> <span class="dv">2</span></a>
|
|
|
<a class="sourceLine" id="cb5-8" data-line-number="8"></a>
|
|
|
<a class="sourceLine" id="cb5-9" data-line-number="9"><span class="co"># Calculate the sum, difference, product, and quotient</span></a>
|
|
|
<a class="sourceLine" id="cb5-10" data-line-number="10">result_sum <span class="op">=</span> x <span class="op">+</span> y</a>
|
|
|
<a class="sourceLine" id="cb5-11" data-line-number="11">result_difference <span class="op">=</span> x <span class="op">-</span> y</a>
|
|
|
<a class="sourceLine" id="cb5-12" data-line-number="12"><span class="co"># </span><span class="al">TODO</span><span class="co">: Multiplication of x and y</span></a>
|
|
|
<a class="sourceLine" id="cb5-13" data-line-number="13"><span class="co"># </span><span class="al">TODO</span><span class="co">: Division of x and y</span></a>
|
|
|
<a class="sourceLine" id="cb5-14" data-line-number="14"></a>
|
|
|
<a class="sourceLine" id="cb5-15" data-line-number="15"><span class="co"># Print out all results</span></a>
|
|
|
<a class="sourceLine" id="cb5-16" data-line-number="16"><span class="bu">print</span>(<span class="st">"result sum"</span>, result_sum)</a>
|
|
|
<a class="sourceLine" id="cb5-17" data-line-number="17"><span class="bu">print</span>(<span class="st">"result difference"</span>, result_difference)</a>
|
|
|
<a class="sourceLine" id="cb5-18" data-line-number="18"><span class="co"># </span><span class="al">TODO</span><span class="co">: Print result product</span></a>
|
|
|
<a class="sourceLine" id="cb5-19" data-line-number="19"><span class="co"># </span><span class="al">TODO</span><span class="co">: Print result quotient</span></a></code></pre></div>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="quick-review" class="level2">
|
|
|
<h2>Quick Review:</h2>
|
|
|
<p>Floor division:</p>
|
|
|
<ul>
|
|
|
<li>Drops the decimal point - always rounds down.</li>
|
|
|
<li>Performed using <code>//</code> instead of just <code>/</code>.</li>
|
|
|
<li>Returns an int instead of a float.</li>
|
|
|
</ul>
|
|
|
<div class="sourceCode" id="cb6"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb6-1" data-line-number="1"><span class="co"># Gives 2.5</span></a>
|
|
|
<a class="sourceLine" id="cb6-2" data-line-number="2">regular_division <span class="op">=</span> <span class="dv">5</span> <span class="op">/</span> <span class="dv">2</span></a>
|
|
|
<a class="sourceLine" id="cb6-3" data-line-number="3"></a>
|
|
|
<a class="sourceLine" id="cb6-4" data-line-number="4"><span class="co"># Gives 2!</span></a>
|
|
|
<a class="sourceLine" id="cb6-5" data-line-number="5">floor_divison <span class="op">=</span> <span class="dv">5</span> <span class="op">//</span> <span class="dv">2</span></a></code></pre></div>
|
|
|
<p><strong>Next up:</strong> Specialty Strings!</p>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>Do a quick check for understanding.</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="switching-gears-strings" class="level2">
|
|
|
<h2>Switching Gears: Strings</h2>
|
|
|
<p>Our intermediate variables checklist: - Floats - Floor division</p>
|
|
|
<p>What about strings? We might want:</p>
|
|
|
<ul>
|
|
|
<li>Printing special characters: A newline, a tab, or a quote inside of a string.</li>
|
|
|
<li>Formatting
|
|
|
<ul>
|
|
|
<li>A string.</li>
|
|
|
<li>The way an integer or float prints out.</li>
|
|
|
</ul></li>
|
|
|
</ul>
|
|
|
<p><strong>Discussion</strong>: How would you go about printing a new line between strings, like below?</p>
|
|
|
<pre><code>Hello!
|
|
|
This is a line later.</code></pre>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>If they think they can just type a new line in with the enter key, challenge them to try it.</li>
|
|
|
</ul>
|
|
|
<p><strong>Talking Points</strong>:</p>
|
|
|
<ul>
|
|
|
<li>“We’ve talked a bit about numbers, but we haven’t even yet touched on more advanced things to do with strings yet!”</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="special-string-characters" class="level2">
|
|
|
<h2>Special String Characters</h2>
|
|
|
<table>
|
|
|
<thead>
|
|
|
<tr class="header">
|
|
|
<th>Name</th>
|
|
|
<th>Escape Character</th>
|
|
|
<th>Notes</th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
<tbody>
|
|
|
<tr class="odd">
|
|
|
<td>Newline</td>
|
|
|
<td></td>
|
|
|
<td>Whitespace: Inserts another line</td>
|
|
|
</tr>
|
|
|
<tr class="even">
|
|
|
<td>Tab</td>
|
|
|
<td></td>
|
|
|
<td>Whitespace: Inserts a tab</td>
|
|
|
</tr>
|
|
|
<tr class="odd">
|
|
|
<td>Quote</td>
|
|
|
<td>"</td>
|
|
|
<td>Print a double quote, don’t end the string</td>
|
|
|
</tr>
|
|
|
<tr class="even">
|
|
|
<td>Backslash</td>
|
|
|
<td>\</td>
|
|
|
<td>Prints \</td>
|
|
|
</tr>
|
|
|
</tbody>
|
|
|
</table>
|
|
|
<div class="sourceCode" id="cb8"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb8-1" data-line-number="1">quote <span class="op">=</span> <span class="st">"</span><span class="ch">\"</span><span class="st">These are not the droids you're looking for.</span><span class="ch">\"\n\n\t</span><span class="st">-Obi-Wan Kenobi</span><span class="ch">\n</span><span class="st">"</span></a>
|
|
|
<a class="sourceLine" id="cb8-2" data-line-number="2"></a>
|
|
|
<a class="sourceLine" id="cb8-3" data-line-number="3"><span class="bu">print</span>(quote)</a></code></pre></div>
|
|
|
<p>This prints, <em>including</em> the quotation marks:</p>
|
|
|
<pre><code>"These are not the droids you're looking for."
|
|
|
|
|
|
|
|
|
- Obi-Wan Kenobi
|
|
|
|
|
|
</code></pre>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>Talk about how they all use the backslash - the backslash escapes.</li>
|
|
|
</ul>
|
|
|
<p><strong>Talking Points</strong>:</p>
|
|
|
<ul>
|
|
|
<li>“You can’t always print everything you want to inside of a string. For example, what if you want to print a quote? How can you distinguish it from the quotes that delineate the string value in Python?”</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="string-format" class="level2">
|
|
|
<h2>String Format</h2>
|
|
|
<p>What else with strings?</p>
|
|
|
<p>String formatting uses index numbers, in <code>{}</code>, as placeholders for strings we later specify in <code>format</code>.</p>
|
|
|
<p>Indexes inside the braces refer to the arguments, in order!</p>
|
|
|
<div class="sourceCode" id="cb10"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb10-1" data-line-number="1"><span class="co">## Indexes count from 0. ##</span></a>
|
|
|
<a class="sourceLine" id="cb10-2" data-line-number="2">x <span class="op">=</span> <span class="st">"</span><span class="sc">{0}</span><span class="st">, </span><span class="sc">{1}</span><span class="st">, </span><span class="sc">{2}</span><span class="st">"</span>.<span class="bu">format</span>(<span class="st">"man"</span>, <span class="st">"bear"</span>, <span class="st">"pig"</span>)</a>
|
|
|
<a class="sourceLine" id="cb10-3" data-line-number="3"><span class="bu">print</span>(x) <span class="co"># prints "man, bear, pig"</span></a>
|
|
|
<a class="sourceLine" id="cb10-4" data-line-number="4"></a>
|
|
|
<a class="sourceLine" id="cb10-5" data-line-number="5"><span class="co">## They don't need to be in order ##</span></a>
|
|
|
<a class="sourceLine" id="cb10-6" data-line-number="6">x <span class="op">=</span> <span class="st">"</span><span class="sc">{1}</span><span class="st">, </span><span class="sc">{0}</span><span class="st">, </span><span class="sc">{2}</span><span class="st">"</span>.<span class="bu">format</span>(<span class="st">"man"</span>, <span class="st">"bear"</span>, <span class="st">"pig"</span>)</a>
|
|
|
<a class="sourceLine" id="cb10-7" data-line-number="7"><span class="bu">print</span>(x) <span class="co"># prints "bear, man, pig"</span></a>
|
|
|
<a class="sourceLine" id="cb10-8" data-line-number="8"></a>
|
|
|
<a class="sourceLine" id="cb10-9" data-line-number="9"><span class="co">## We can repeat! ##</span></a>
|
|
|
<a class="sourceLine" id="cb10-10" data-line-number="10">x <span class="op">=</span> <span class="st">"</span><span class="sc">{0}</span><span class="st"> </span><span class="sc">{1}</span><span class="st"> </span><span class="sc">{0}</span><span class="st"> </span><span class="sc">{1}</span><span class="st"> </span><span class="sc">{0}</span><span class="st">"</span>.<span class="bu">format</span>(<span class="st">"Hello"</span>, <span class="st">"World"</span>)</a>
|
|
|
<a class="sourceLine" id="cb10-11" data-line-number="11"><span class="bu">print</span>(x) <span class="co"># prints "Hello World Hello World Hello"</span></a></code></pre></div>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>Note the syntax -</li>
|
|
|
<li>Talk about why you’d do this versus print(“man”, “bear”, “pig”)</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="escaping-and-format" class="level2">
|
|
|
<h2>Escaping and Format</h2>
|
|
|
<p>Check it out:</p>
|
|
|
<iframe height="400px" width="100%" src="https://repl.it/@SuperTernary/python-programming-string-formatting?lite=true" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals">
|
|
|
</iframe>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>This isn’t an exercise - it’s a demo to show and gain students’ understanding.</li>
|
|
|
<li>Show several variants of poking around with this code! Maybe demonstrate some more escape characters.</li>
|
|
|
</ul>
|
|
|
<p><strong>Talking Points</strong>:</p>
|
|
|
<ul>
|
|
|
<li>“Let’s put the concepts of escaping characters with backslash and format to make a shortened version of some Beatles lyrics”</li>
|
|
|
</ul>
|
|
|
<p><strong>Repl.it Note</strong>: This replit has</p>
|
|
|
<div class="sourceCode" id="cb11"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb11-1" data-line-number="1"><span class="co"># Two ways to print the same thing</span></a>
|
|
|
<a class="sourceLine" id="cb11-2" data-line-number="2"></a>
|
|
|
<a class="sourceLine" id="cb11-3" data-line-number="3"><span class="co"># First way</span></a>
|
|
|
<a class="sourceLine" id="cb11-4" data-line-number="4">lyrics <span class="op">=</span> <span class="st">"let it be, let it be, let it be, let it be</span><span class="ch">\n</span><span class="st">whisper words of wisdom</span><span class="ch">\n</span><span class="st">let it be</span><span class="ch">\n</span><span class="st">"</span></a>
|
|
|
<a class="sourceLine" id="cb11-5" data-line-number="5"></a>
|
|
|
<a class="sourceLine" id="cb11-6" data-line-number="6"><span class="bu">print</span>(lyrics)</a>
|
|
|
<a class="sourceLine" id="cb11-7" data-line-number="7"></a>
|
|
|
<a class="sourceLine" id="cb11-8" data-line-number="8"><span class="co"># Second way, with format</span></a>
|
|
|
<a class="sourceLine" id="cb11-9" data-line-number="9">let_it_be <span class="op">=</span> <span class="st">"let it be"</span></a>
|
|
|
<a class="sourceLine" id="cb11-10" data-line-number="10">whisper <span class="op">=</span> <span class="st">"whisper words of wisdom"</span></a>
|
|
|
<a class="sourceLine" id="cb11-11" data-line-number="11"></a>
|
|
|
<a class="sourceLine" id="cb11-12" data-line-number="12"><span class="bu">print</span>(<span class="st">"</span><span class="sc">{0}</span><span class="st">, </span><span class="sc">{0}</span><span class="st">, </span><span class="sc">{0}</span><span class="st">, </span><span class="sc">{0}</span><span class="ch">\n</span><span class="sc">{1}</span><span class="ch">\n</span><span class="sc">{0}</span><span class="st">"</span>.<span class="bu">format</span>(let_it_be, whisper))</a></code></pre></div>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="quick-review-1" class="level2">
|
|
|
<h2>Quick Review</h2>
|
|
|
<p>Special strings:</p>
|
|
|
<ul>
|
|
|
<li>A backslash <code>\</code> escapes special characters: <code>\"</code> will print a quote and <code>\\</code> prints a <code>\</code>.</li>
|
|
|
<li><code>\n</code> creates a New line; <code>\t</code> creates a Tab.</li>
|
|
|
</ul>
|
|
|
<p>String formatting:</p>
|
|
|
<ul>
|
|
|
<li>Can be used when printing or creating new strings.</li>
|
|
|
<li>Use <code>{x}</code>; <code>x</code> corresponds to the number of the argument.</li>
|
|
|
</ul>
|
|
|
<div class="sourceCode" id="cb12"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb12-1" data-line-number="1">x <span class="op">=</span> <span class="st">"</span><span class="sc">{0}</span><span class="st">, </span><span class="sc">{1}</span><span class="st">, </span><span class="sc">{2}</span><span class="st">"</span>.<span class="bu">format</span>(<span class="st">"man"</span>, <span class="st">"bear"</span>, <span class="st">"pig"</span>)</a>
|
|
|
<a class="sourceLine" id="cb12-2" data-line-number="2"><span class="bu">print</span>(x) <span class="co"># prints "man, bear, pig"</span></a>
|
|
|
<a class="sourceLine" id="cb12-3" data-line-number="3"></a>
|
|
|
<a class="sourceLine" id="cb12-4" data-line-number="4">x <span class="op">=</span> <span class="st">"</span><span class="sc">{1}</span><span class="st">, </span><span class="sc">{0}</span><span class="st">, </span><span class="sc">{2}</span><span class="st">"</span>.<span class="bu">format</span>(<span class="st">"man"</span>, <span class="st">"bear"</span>, <span class="st">"pig"</span>)</a>
|
|
|
<a class="sourceLine" id="cb12-5" data-line-number="5"><span class="bu">print</span>(x) <span class="co"># prints "bear, man, pig"</span></a>
|
|
|
<a class="sourceLine" id="cb12-6" data-line-number="6"></a>
|
|
|
<a class="sourceLine" id="cb12-7" data-line-number="7">x <span class="op">=</span> <span class="st">"</span><span class="sc">{0}</span><span class="st"> </span><span class="sc">{1}</span><span class="st"> </span><span class="sc">{0}</span><span class="st"> </span><span class="sc">{1}</span><span class="st"> </span><span class="sc">{0}</span><span class="st">"</span>.<span class="bu">format</span>(<span class="st">"Hello"</span>, <span class="st">"World"</span>)</a>
|
|
|
<a class="sourceLine" id="cb12-8" data-line-number="8"><span class="bu">print</span>(x) <span class="co"># prints "Hello World Hello World Hello"</span></a></code></pre></div>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>Do a quick check for understanding.</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="number-format" class="level2">
|
|
|
<h2>Number Format</h2>
|
|
|
<p>What about number formatting?</p>
|
|
|
<ul>
|
|
|
<li>Specify a float’s precision (how many decimal points are shown).</li>
|
|
|
<li>Add commas to an integer (so it’s more readable!).</li>
|
|
|
</ul>
|
|
|
<div class="sourceCode" id="cb13"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb13-1" data-line-number="1">x <span class="op">=</span> <span class="bu">format</span>(<span class="dv">1</span><span class="op">/</span><span class="dv">3</span>, <span class="st">'.2f'</span>)</a>
|
|
|
<a class="sourceLine" id="cb13-2" data-line-number="2"><span class="bu">print</span>(x) <span class="co"># Technically, 1/3 is .333333333333. This prints "0.33"</span></a>
|
|
|
<a class="sourceLine" id="cb13-3" data-line-number="3">x <span class="op">=</span> <span class="bu">format</span>(<span class="fl">2.0024292</span>, <span class="st">'.3f'</span>)</a>
|
|
|
<a class="sourceLine" id="cb13-4" data-line-number="4"><span class="bu">print</span>(x) <span class="co"># This prints "2.002"</span></a></code></pre></div>
|
|
|
<div class="sourceCode" id="cb14"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb14-1" data-line-number="1">x <span class="op">=</span> <span class="bu">format</span>(<span class="dv">5200</span>, <span class="st">',d'</span>)</a>
|
|
|
<a class="sourceLine" id="cb14-2" data-line-number="2"><span class="bu">print</span>(x) <span class="co"># Prints "5,200"</span></a></code></pre></div>
|
|
|
<p><strong>Note: Number formatting creates strings!</strong></p>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>Break down the syntax. What does <code>.2f</code> mean? What does <code>,d</code> mean?</li>
|
|
|
<li>Give many examples for formatting. <code>.5f</code>; things besides <code>,d</code>. Ask them to come up with something they’d like to do, and research with them (if you don’t know) the syntax to do it.</li>
|
|
|
</ul>
|
|
|
<p><strong>Talking Points</strong>:</p>
|
|
|
<ul>
|
|
|
<li>“We can also use the format function with numbers. Beware: the result is a string!”</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="you-do-bring-it-all-together" class="level2">
|
|
|
<h2>You Do: Bring It All Together!</h2>
|
|
|
<ul>
|
|
|
<li><p>Open a new file and name it “solution.py”.</p></li>
|
|
|
<li><p>Make a dictionary called “sports” with at least 4 key / value pairs.</p>
|
|
|
<ul>
|
|
|
<li>Keys are the names (e.g., tennis, soccer, volleyball).</li>
|
|
|
<li>Values are the the number of people that play in a game.</li>
|
|
|
</ul></li>
|
|
|
<li><p>Use a loop to print out all the keys and values.</p>
|
|
|
<ul>
|
|
|
<li>Output:</li>
|
|
|
</ul>
|
|
|
<pre><code>I like "tennis".
|
|
|
There are usually 2 players in tennis.</code></pre>
|
|
|
<ul>
|
|
|
<li>Note the new line and quotes, and use <code>format</code> to print out your string!</li>
|
|
|
</ul></li>
|
|
|
<li><p>BONUS: Every other sport, indent by another tab.</p>
|
|
|
<ul>
|
|
|
<li>0 tabs: Tennis.</li>
|
|
|
<li>1 tab level: Soccer.</li>
|
|
|
<li>2 tab levels: Volleyball.</li>
|
|
|
</ul></li>
|
|
|
</ul>
|
|
|
<p><strong>HINT</strong>: Use floor division for the bonus! <code>number_of_tabs = loop_counter // 2</code></p>
|
|
|
<aside class="notes">
|
|
|
<p>5 minutes</p>
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>Give students a few minutes to do this; walk around the room. When the majority are done, go over the answer.</li>
|
|
|
<li>The floor division portion is listed as a bonus, but <em>please</em> do go over this when you review the answer to the problem!</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="summary-and-qa" class="level2">
|
|
|
<h2>Summary and Q&A</h2>
|
|
|
<ul>
|
|
|
<li>Floats (<code>2.52</code>)</li>
|
|
|
<li>Floor (<code>int_index = 5 // 2</code>) - creates an int.</li>
|
|
|
<li>Escape characters (<code>\\</code>, <code>\n</code>, <code>\r</code>, <code>\t</code>, <code>\"</code>)</li>
|
|
|
<li>Formatting:</li>
|
|
|
</ul>
|
|
|
<div class="sourceCode" id="cb16"><pre class="sourceCode python"><code class="sourceCode python"><a class="sourceLine" id="cb16-1" data-line-number="1">x <span class="op">=</span> <span class="st">"</span><span class="sc">{0}{1}{0}</span><span class="st">"</span>.<span class="bu">format</span>(<span class="st">"Hello"</span>, <span class="st">"World"</span>)</a>
|
|
|
<a class="sourceLine" id="cb16-2" data-line-number="2"><span class="bu">print</span>(x) <span class="co"># prints "HelloWorldHello"</span></a>
|
|
|
<a class="sourceLine" id="cb16-3" data-line-number="3"></a>
|
|
|
<a class="sourceLine" id="cb16-4" data-line-number="4">x <span class="op">=</span> <span class="bu">format</span>(<span class="dv">5200</span>, <span class="st">',d'</span>) <span class="co"># "5,200" -> A string!</span></a>
|
|
|
<a class="sourceLine" id="cb16-5" data-line-number="5"></a>
|
|
|
<a class="sourceLine" id="cb16-6" data-line-number="6">x <span class="op">=</span> <span class="bu">format</span>(<span class="dv">1</span><span class="op">/</span><span class="dv">3</span>, <span class="st">'.2f'</span>) <span class="co"># 0.33</span></a></code></pre></div>
|
|
|
<ul>
|
|
|
<li>Type conversion:
|
|
|
<ul>
|
|
|
<li><code>int()</code></li>
|
|
|
<li><code>float()</code></li>
|
|
|
<li><code>str()</code></li>
|
|
|
</ul></li>
|
|
|
</ul>
|
|
|
<aside class="notes">
|
|
|
<p><strong>Teaching Tips</strong>:</p>
|
|
|
<ul>
|
|
|
<li>Make sure the students are comfortable with the material. Prod them for questions and remind them that programming is hard and that there aren’t bad questions.</li>
|
|
|
</ul>
|
|
|
</aside>
|
|
|
<hr />
|
|
|
</section>
|
|
|
<section id="additional-resources" class="level2">
|
|
|
<h2>Additional Resources</h2>
|
|
|
<ul>
|
|
|
<li><a href="https://docs.python.org/3/tutorial/floatingpoint.html">Floating Point (Docs)</a></li>
|
|
|
<li><a href="https://docs.python.org/3/library/decimal.html">Decimal Module</a></li>
|
|
|
<li><a href="http://python-reference.readthedocs.io/en/latest/docs/operators/floor_division.html">Floor Division</a></li>
|
|
|
<li><a href="https://linuxconfig.org/list-of-python-escape-sequence-characters-with-examples">List of Escape Characters</a></li>
|
|
|
<li><a href="https://en.wikipedia.org/wiki/List_of_Unicode_characters">List of Unicode Characters</a></li>
|
|
|
<li><a href="http://jrgraphix.net/r/Unicode">Obscure Unicode Characters</a></li>
|
|
|
<li><a href="https://en.wikipedia.org/wiki/List_of_Unicode_characters">Unicode Database</a></li>
|
|
|
</ul>
|
|
|
</section>
|
|
|
|
|
|
</div>
|
|
|
<footer><span class='slide-number'></span></footer>
|
|
|
</div>
|
|
|
<script src="../../../../lib/js/head.min.js"></script>
|
|
|
<script src="../../../../js/reveal.js"></script>
|
|
|
|
|
|
<script>
|
|
|
|
|
|
var dependencies = [
|
|
|
{ src: '../../../../lib/js/classList.js', condition: function() { return !document.body.classList; } },
|
|
|
{ src: '../../../../plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
|
|
|
{ src: '../../../../plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
|
|
|
{ src: '../../../../plugin/prism/prism.js', async: true, callback: function() { /*hljs.initHighlightingOnLoad();*/ } },
|
|
|
{ src: '../../../../plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } }
|
|
|
];
|
|
|
|
|
|
if (Reveal.getQueryHash().instructor === 1) {
|
|
|
dependencies.push({ src: '../../../../plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } });
|
|
|
}
|
|
|
// Full list of configuration options available here:
|
|
|
// https://github.com/hakimel/reveal.js#configuration
|
|
|
Reveal.initialize({
|
|
|
controls: true,
|
|
|
progress: true,
|
|
|
history: true,
|
|
|
center: false,
|
|
|
slideNumber: true,
|
|
|
|
|
|
// available themes are in /css/theme
|
|
|
theme: Reveal.getQueryHash().theme || 'default',
|
|
|
|
|
|
// default/cube/page/concave/zoom/linear/fade/none
|
|
|
transition: Reveal.getQueryHash().transition || 'slide',
|
|
|
|
|
|
// Optional libraries used to extend on reveal.js
|
|
|
dependencies: dependencies
|
|
|
});
|
|
|
|
|
|
if (Reveal.getQueryHash().instructor === 1) {
|
|
|
Reveal.configure(dependencies.push({ src: '../../../../plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }));
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Reveal.addEventListener('ready', function() {
|
|
|
if (Reveal.getCurrentSlide().classList.contains('separator-subhead')) {
|
|
|
document.getElementById('theme').setAttribute('href', '../../../../css/theme/ga-subhead.css');
|
|
|
} else if (Reveal.getCurrentSlide().classList.contains('separator')) {
|
|
|
document.getElementById('theme').setAttribute('href', '../../../../css/theme/ga-title.css')
|
|
|
} else {
|
|
|
document.getElementById('theme').setAttribute('href', '../../../../css/theme/ga.css');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
Reveal.addEventListener('slidechanged', function(e) {
|
|
|
if (Reveal.getCurrentSlide().classList.contains('separator-subhead')) {
|
|
|
document.getElementById('theme').setAttribute('href', '../../../../css/theme/ga-subhead.css');
|
|
|
} else if (Reveal.getCurrentSlide().classList.contains('separator')) {
|
|
|
document.getElementById('theme').setAttribute('href', '../../../../css/theme/ga-title.css')
|
|
|
} else {
|
|
|
document.getElementById('theme').setAttribute('href', '../../../../css/theme/ga.css');
|
|
|
}
|
|
|
});
|
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
</html>
|