summaryrefslogtreecommitdiff
path: root/basic_python
diff options
context:
space:
mode:
Diffstat (limited to 'basic_python')
-rw-r--r--basic_python/practice_control_flow.tex26
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