diff options
author | Prabhu Ramachandran | 2017-02-07 10:41:48 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2017-02-07 10:41:48 +0530 |
commit | 5bcd987d702e5e8653538713c0f48889853eef7a (patch) | |
tree | 24a8781b5b652dcd4bea1f69c7bdaeb698cb37a3 /basic_python | |
parent | a04df04e9a114a8eac0af5b8dcce38a31ef1d313 (diff) | |
download | python-workshops-5bcd987d702e5e8653538713c0f48889853eef7a.tar.gz python-workshops-5bcd987d702e5e8653538713c0f48889853eef7a.tar.bz2 python-workshops-5bcd987d702e5e8653538713c0f48889853eef7a.zip |
Add nested for example.
Diffstat (limited to 'basic_python')
-rw-r--r-- | basic_python/practice_control_flow.tex | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/basic_python/practice_control_flow.tex b/basic_python/practice_control_flow.tex index b0ff7a2..5ce053f 100644 --- a/basic_python/practice_control_flow.tex +++ b/basic_python/practice_control_flow.tex @@ -349,6 +349,32 @@ from __future__ import print_function \end{frame} \begin{frame}[plain,fragile] + \frametitle{Nested \typ{for} loops} + \begin{enumerate} + \item Let us say the user supplies an integer, \typ{n} (empty prompt) + \item Print an n x n matrix where each entry is the sum of the row + column + \end{enumerate} + For example let us say user enters \typ{3}, print + \begin{lstlisting} + 0 1 2 + 1 2 3 + 2 3 4 + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile,plain] +\frametitle{Solution} +\begin{lstlisting} + n = input() + for i in range(n): + for j in range(n): + print(i+j, end=' ') + print() +\end{lstlisting} +\end{frame} + + +\begin{frame}[plain,fragile] \frametitle{Exercise: Fibonacci divisible by 4} \begin{enumerate} \item Find the first number in the Fibonacci sequence divisible by 4 but > 8 |