summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tuples/script.rst213
-rw-r--r--tuples/slides.org89
-rw-r--r--tuples/slides.tex124
3 files changed, 319 insertions, 107 deletions
diff --git a/tuples/script.rst b/tuples/script.rst
index 23d88b2..297c90f 100644
--- a/tuples/script.rst
+++ b/tuples/script.rst
@@ -21,62 +21,123 @@
Script
------
-Hello friends and welcome to the tutorial on getting started with
-tuples.
+.. L1
-{{{ Show the slide containing title }}}
+{{{ Show the first slide containing title, name of the production
+team along with the logo of MHRD }}}
-{{{ Show the slide containing the outline slide }}}
+.. R1
-In this tutorial, we shall learn
+Hello friends and welcome to the tutorial on "getting started with
+tuples".
- * what are tuples
- * their similarities and dissimilarities with lists
- * why are they needed
+.. L2
+
+{{{ Show the slide containing the objectives }}}
+
+.. R2
+
+At the end of the tutorial, you will be able to,
+
+ 1. Understand of what tuples are.
+ #. Compare them with lists.
+ #. Know why they are needed and where to use them.
+
+.. L3
+
+{{{ Switch to the pre-requisite slide }}}
+
+.. R3
+
+Before beginning this tutorial,we would suggest you to complete the
+tutorial on "Getting started with lists".
+
+.. R4
+
+Let us start our ipython interpreter.
+
+.. L4
+
+{{{ Open the terminal }}}
+::
+
+ ipython
+
+.. R5
Let's get started by defining a tuple. A tuple is defined by enclosing
parentheses around a sequence of items seperated by commas. It is
similar to defining a list except that parentheses are used instead of
square brackets.
+
+.. L5
::
t = (1, 2.5, "hello", -4, "world", 1.24, 5)
t
-defines a tuple. The items in the tuple are indexed using numbers and can be
-accessed by using their position.
+.. R6
+
+The items in the tuple are indexed using numbers and can be
+accessed by using their position.For example,
+
+.. L6
::
t[3]
-prints -4 which is the fourth item of the tuple.
+.. R7
+It prints -4 which is the fourth item of the tuple
+Similarly,
+
+.. L7
::
t[1:5:2]
-prints the corresponding slice
+.. R8
+
+It prints the corresponding slice
-This is the behaviour similar as to lists. But the difference can be seen when
-we try to change an element in the tuple.
+This behaviour is similar to that of lists. But the difference can be
+seen when we try to change an element in the tuple.
+
+.. L8
::
t[2] = "Hello"
-We can see that, it raises an error saying tuple does not support item
-assignment. Tuples are immutable, and cannot be changed after
+.. R9
+
+We can see that, it raises an error saying 'tuple object does not support
+item assignment'. Tuples are immutable, and hence cannot be changed after
creation.
-Then, what's the use of tuples?
+Then, what is the use of tuples?
+We shall understand that soon. But let us look at a simple problem of
+swapping values.
+
+Pause the video here, try out the following exercise and resume the video.
+
+.. L9
-We shall understand that soon. But let us look at a simple problem of swapping
-values.
+.. L10
-{{{ Pause here and try out the following exercises }}}
+{{{ Show slide with exercise 1 }}}
-%% 1 %% a = 5 and b = 7. swap the values of a and b
+.. R10
+
+ Given, a = 5 and b = 7. Swap the values of a and b.
+
+.. R11
+
+Switch to terminal fo solution
+
+.. L11
{{{ continue from paused state }}}
+{{{ Switch to the terminal }}}
::
a = 5
@@ -85,7 +146,11 @@ values.
a
b
-We define the two values
+.. R12
+
+We now create a variable say, temp and swap the values using this variable
+
+.. L12
::
temp = a
@@ -95,9 +160,12 @@ We define the two values
a
b
-This is the traditional approach
+.. R13
+This is the traditional approach
Now let us do it the python way
+
+.. L13
::
a
@@ -108,64 +176,125 @@ Now let us do it the python way
a
b
+.. R14
+
We see that the values are swapped. This idiom works for different
data-types also.
+.. L14
::
a = 2.5
b = "hello"
-
+ a, b = b, a
a
b
+.. R15
+
Moreover this type of behaviour is something that feels natural and
you'd expect to happen.
-This is possible because of the immutability of tuples. This process is called
-tuple packing and unpacking.
+This is possible because of the immutability of tuples. This process is
+called tuple packing and unpacking.
Let us first see what is tuple packing. Type
+
+.. L15
::
5,
+.. R16
+
What we see is a tuple with one element.
+
+.. L16
::
5, "hello", 2.5
+.. R17
+
Now it is a tuple with three elements.
-So when we are actually typing two or more elements seperated by commas, those
-elements are packed into a tuple.
+So when we are actually typing two or more elements seperated by commas,
+those elements are packed into a tuple.
When you type
-::
a, b = b, a
-First the values of b and a are packed into a tuple on the right side and then
-unpacked into the variables a and b.
+First the values of b and a are packed into a tuple on the right side
+and then unpacked into the variables a and b.
Immutability of tuples ensures that the values are not changed during the
packing and unpacking.
+.. L17
+
+.. L18
+
{{{ Show summary slide }}}
-This brings us to the end of the tutorial.
-we have learnt
+.. R18
+
+This brings us to the end of this tutorial.In this tutorial,
+we have learnt to,
+
+ 1. Define tuples.
+ #. Understand the similarities of tuples with lists, like indexing and
+ iterability.
+ #. Know about the immutability of tuples.
+ #. Swap values, the python way.
+ #. Understand the concept of packing and unpacking of tuples.
+
+.. L19
+
+{{{Show self assessment questions slide}}}
+
+.. R19
+
+Here are some self assessment questions for you to solve
+
+1. Define a tuple containing two values. The first being integer 4 and
+ second is a float 2.5
+
+2. If ``a = 5,`` then what is the type of a ?
+
+ - int
+ - float
+ - tuple
+ - string
+
+3. if ``a = (2, 3)``. What does ``a[0], a[1] = (3, 4)`` produce
+
+.. L20
+
+{{{solution of self assessment questions on slide}}}
+
+.. R20
+
+And the answers,
+
+1. A tuple is defined by enclosing parentheses around a sequence of
+ items seperated by commas.Hence, we write our tuple as,
+::
+
+ (4, 2.5)
+
+2. Since the given data is 5 followed by a comma, it means that it is
+ a tuple
+
+3. The operation a[0], a[1] = (3, 4) will result in an error because
+ tuples are immutable.
- * How to define tuples
- * The similarities of tuples with lists, like indexing and iterability
- * The immutability of tuples
- * The value swapping idiom in Python
- * packing and unpacking of tuples
+.. L21
-{{{ Show the "sponsored by FOSSEE" slide }}}
+{{{ Show the thankyou slide }}}
-This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
+.. R21
-Hope you have enjoyed and found it useful.
-Thank you
+Hope you have enjoyed this tutorial and found it useful.
+Thank you!
diff --git a/tuples/slides.org b/tuples/slides.org
index d1b0d6a..4b718fa 100644
--- a/tuples/slides.org
+++ b/tuples/slides.org
@@ -18,7 +18,7 @@
#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-#+TITLE: Getting started -- Tuples
+#+TITLE:
#+AUTHOR: FOSSEE
#+EMAIL:
#+DATE:
@@ -29,39 +29,72 @@
#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
-* Outline
- - what are tuples
- - comparison with lists
- - why are they needed
-* Question 1
- ~a = 5~ and ~b = 7~. swap the values of ~a~ and ~b~
-* Solution 1
- #+begin_src python
- temp = a
- a = b
- b = temp
-
- a
- b
- #+end_src
+*
+ #+begin_latex
+\begin{center}
+\vspace{12pt}
+\textcolor{blue}{\huge Getting started with \texttt{tuples}}
+\end{center}
+\vspace{18pt}
+\begin{center}
+\vspace{10pt}
+\includegraphics[scale=0.95]{../images/fossee-logo.png}\\
+\vspace{5pt}
+\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\
+\scriptsize Funded by National Mission on Education through ICT\\
+\scriptsize MHRD,Govt. of India\\
+\includegraphics[scale=0.30]{../images/iitb-logo.png}\\
+\end{center}
+#+end_latex
+* Objectives
+ At the end of the tutorial, you will be able to,
+
+ - Understand of what tuples are.
+ - Compare them with lists.
+ - Know why they are needed and where to use them.
+* Pre-requisite
+Spoken tutorial on -
+- Getting started with Lists
+* Exericse 1
+ Given, ~a = 5~ and ~b = 7~. Swap the values of ~a~ and ~b~.
* Summary
- You should now --
- + Be able to define tuples
- + Know the similarities with lists, like -- indexing and iterability
- + Know about the immutability of tuples
- + Be able to swap variables in the Pythonic way
- + Know about packing and unpacking of tuples
-* Thank you!
+ In this tutorial, we have learnt to,
+
+ - Define tuples.
+ - Understand the similarities of tuples with lists, like indexing and
+ iterability.
+ - Know about the immutability of tuples.
+ - Swap values, the python way.
+ - Understand the concept of packing and unpacking of tuples.
+* Evaluation
+1. Define a tuple containing two values. The first being integer 4 and
+ second is a float 2.5
+
+2. If ``a = 5,'' then what is the type of a ?
+
+ - int
+ - float
+ - tuple
+ - string
+
+3. If ``a = (2, 3)''. What does ``a[ 0 ], a[ 1 ] = (3, 4)'' produce ?
+* Solutions
+1. (4, 2.5)
+
+2. tuple
+
+3. Error
+*
#+begin_latex
\begin{block}{}
\begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
+ \textcolor{blue}{\Large THANK YOU!}
\end{center}
+ \end{block}
+\begin{block}{}
\begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
+ For more Information, visit our website\\
+ \url{http://fossee.in/}
\end{center}
\end{block}
#+end_latex
diff --git a/tuples/slides.tex b/tuples/slides.tex
index 375ff07..cd8c71c 100644
--- a/tuples/slides.tex
+++ b/tuples/slides.tex
@@ -1,4 +1,4 @@
-% Created 2010-10-10 Sun 23:03
+% Created 2011-07-05 Tue 10:27
\documentclass[presentation]{beamer}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
@@ -23,14 +23,14 @@ commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
showstringspaces=false, keywordstyle=\color{blue}\bfseries}
\providecommand{\alert}[1]{\textbf{#1}}
-\title{Getting started -- Tuples}
+\title{}
\author{FOSSEE}
\date{}
\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
\begin{document}
-\maketitle
+
@@ -41,63 +41,113 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries}
\begin{frame}
-\frametitle{Outline}
-\label{sec-1}
-\begin{itemize}
-\item what are tuples
-\item comparison with lists
-\item why are they needed
-\end{itemize}
+\begin{center}
+\vspace{12pt}
+\textcolor{blue}{\huge Getting started with \texttt{tuples}}
+\end{center}
+\vspace{18pt}
+\begin{center}
+\vspace{10pt}
+\includegraphics[scale=0.95]{../images/fossee-logo.png}\\
+\vspace{5pt}
+\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\
+\scriptsize Funded by National Mission on Education through ICT\\
+\scriptsize MHRD,Govt. of India\\
+\includegraphics[scale=0.30]{../images/iitb-logo.png}\\
+\end{center}
\end{frame}
\begin{frame}
-\frametitle{Question 1}
+\frametitle{Objectives}
\label{sec-2}
- \texttt{a = 5} and \texttt{b = 7}. swap the values of \texttt{a} and \texttt{b}
+ At the end of the tutorial, you will be able to,
+
+
+\begin{itemize}
+\item Understand of what tuples are.
+\item Compare them with lists.
+\item Know why they are needed and where to use them.
+\end{itemize}
\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 1}
+\begin{frame}
+\frametitle{Pre-requisite}
\label{sec-3}
-\lstset{language=Python}
-\begin{lstlisting}
-temp = a
-a = b
-b = temp
+Spoken tutorial on -
-a
-b
-\end{lstlisting}
+\begin{itemize}
+\item Getting started with Lists
+\end{itemize}
\end{frame}
\begin{frame}
-\frametitle{Summary}
+\frametitle{Exericse 1}
\label{sec-4}
- You should now --
+ Given, \verb~a = 5~ and \verb~b = 7~. Swap the values of \verb~a~ and \verb~b~.
+\end{frame}
+\begin{frame}
+\frametitle{Summary}
+\label{sec-5}
+
+ In this tutorial, we have learnt to,
+
+
\begin{itemize}
-\item Be able to define tuples
-\item Know the similarities with lists, like -- indexing and iterability
-\item Know about the immutability of tuples
-\item Be able to swap variables in the Pythonic way
-\item Know about packing and unpacking of tuples
+\item Define tuples.
+\item Understand the similarities of tuples with lists, like indexing and
+ iterability.
+\item Know about the immutability of tuples.
+\item Swap values, the python way.
+\item Understand the concept of packing and unpacking of tuples.
\end{itemize}
\end{frame}
\begin{frame}
-\frametitle{Thank you!}
-\label{sec-5}
+\frametitle{Evaluation}
+\label{sec-6}
+
+
+\begin{enumerate}
+\item Define a tuple containing two values. The first being integer 4 and
+ second is a float 2.5
+\vspace{8pt}
+\item If ``a = 5,'' then what is the type of a ?
+\begin{itemize}
+\item int
+\item float
+\item tuple
+\item string
+\end{itemize}
+\vspace{8pt}
+\item If ``a = (2, 3)'',\\ What does ``a[ 0 ], a[ 1 ] = (3, 4)'' produce ?
+\end{enumerate}
+\end{frame}
+\begin{frame}
+\frametitle{Solutions}
+\label{sec-7}
+
+
+\begin{enumerate}
+\item (4, 2.5)
+\vspace{12pt}
+\item tuple
+\vspace{12pt}
+\item Error
+\end{enumerate}
+\end{frame}
+\begin{frame}
\begin{block}{}
\begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
+ \textcolor{blue}{\Large THANK YOU!}
\end{center}
+ \end{block}
+\begin{block}{}
\begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
+ For more Information, visit our website\\
+ \url{http://fossee.in/}
\end{center}
\end{block}
\end{frame}
-\end{document}
+\end{document} \ No newline at end of file