\documentclass[
% handout,
aspectratio=169
]{beamer}

\usetheme{Rochester}
\hypersetup{colorlinks=false,urlcolor=red}

\usepackage[utf8]{inputenc}
%\DeclareUnicodeCharacter{263A}{\sad}
%\DeclareRobustCommand\sad{%
%  \unskip\nobreak\thinspace\textemdash\allowbreak\thinspace\ignorespaces}
\usepackage[spanish]{babel}

\usepackage{tikzsymbols}
\usepackage{listings}
\lstset{
  basicstyle={\fontsize{8}{7}\selectfont\ttfamily}
}
\input{macros}


\begin{document}
\title{Programinng I}
\author{Luis Llana Díaz}
\institute{Computer Science Departament \\Complutense University of
  Madrid (UCM)}
\maketitle

\def\acc#1{{\color{red}\uppercase{#1}}}

\begin{frame}{Contacto con el profesor}
  \begin{description}
  \item[Nombre] Luis Llana Díaz.
  \item[Despacho] 115 (1ª planta).
  \item[Email] \url{llana@ucm.es} (consultas personales, \textbf{NO} dudas).
  \item[Turorías] L,M,X 13:00-14:00 (previa petición).
  \end{description}
\end{frame}

\begin{frame}
  \frametitle{Recursos digitales}
  \begin{columns}<+->
    \begin{column}{0.7\hsize}
      \begin{block}{Campus Virtual}
        \textbf{NO} se usa el oficial UCM:\\
        \url{https://wild.ucm.es}
        \begin{itemize}
        \item Dudas y consultas.
        \item Anuncios
        \item Material
        \end{itemize}
      \end{block}
    \end{column}
    \begin{column}{0.3\hsize}
      \includegraphics[scale=0.4]{img/wild_qr}
    \end{column}
  \end{columns}

  \begin{columns}<+->
    \begin{column}{0.7\hsize}
      \begin{block}{Servidor con MongoDB}
        \url{https://isabelita.fdi.ucm.es/jupyter}
        \begin{itemize}
        \item Ejercicios y material online
        \end{itemize}
      \end{block}
    \end{column}
    \begin{column}{0.3\hsize}
      \includegraphics[scale=0.4]{img/isabelita_qr}
    \end{column}
  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{Objetives}
  \begin{quote}
    Acquire the essential techniques for developing correct, reusable,
    and efficient small-scale programs, using basic statements,
    structured control flow, and subprograms.
  \end{quote}

  \begin{itemize}
  \item Understand fundamental concepts of programming.
  \item Learn to design, implement, and debug small-scale programs.
  \item Master basic control structures (sequence, selection,
    iteration).
  \item Develop skills in modular programming using functions and
    procedures.
  \item Familiarize with essential data types (numbers, strings,
    lists, tuples, dictionaries).
  \item Practice problem-solving using programming.
  \end{itemize}
\end{frame}



\begin{frame}
  \frametitle{Methodology}
  \begin{itemize}[<+->]
  \item 4 hours a week (2 days).
  \item \textbf{Punctuality} is important.
  \item Make sure that \textbf{mobile is silenced}.
  \item \textbf{Lectures:} (2 hours) Theoretical concepts and small
    examples.
    \onslide<+->{{\color{red}Participation is essential for success.}}
  \item \textbf{Exercises:} made by the students.
    \onslide<+->{{\color{red}In class in advance and at home.}}
    \onslide<+->{2 hours in laboratory}
  \item Evaluation: continuous or final exam
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Continuous Evaluation}
    \begin{description}[<+->]
    \item[Participation:]
      \begin{itemize}
      \item Controlled assistance (QR, small exercise at the end of
        the class)
      \item 5\% max of missing.
      \item Active participation at class (solving problems at the
        blackboard).
      \item {\color{red}10\% of the final grade.}
      \end{itemize}
    \item[Practice]
      \begin{itemize}
      \item a special exercise (practice).
      \item 3 people groups.
      \item Oral presentation.
      \item {\color{red}20\% of the final grade.}
      \end{itemize}
    \item[Partial Exams]
      \begin{itemize}
      \item In paper.
      \item 2 partial exams (40\%, 60\%).
      \item Minimal grade each 4 out of 10.
      \item {\color{red}70\% of the final grade.}
      \end{itemize}
    \end{description}
\end{frame}

\begin{frame}
  \frametitle{Way to success}
  \begin{description}[<+->]
  \onslide<7->{\putAt{8cm}{0cm}{\includegraphics[scale=0.2]{img/JaingHead}}}
  \item[My responsability.]
    To teach you the concepts.
    \onslide<+->{I have prepared material.}
  \item[My wish.]
    You to learn.
    \onslide<+->{I want to solve all your doubts.}
  \item[Your responsability.]
    To learn.
  \item[Your wish.] To pass the subject with good grades.
  \end{description}
  \begin{minipage}{0.4\hsize}
    \begin{block}<+->{This is the way}
      \begin{itemize}[<+->]
      \item Work hard (you and me).
      \item Make the exercises.
      \item Ask all the doubts (you).
      \item Solve your questions (me).
      \end{itemize}
    \end{block}
  \end{minipage}
\end{frame}

\begin{frame}
  \frametitle{What is a Computer?}
  \includegraphics[width=8em]{img/ENIAC-changing_a_tube_(cropped)}
  \includegraphics[width=8em]{img/IBM_System360_Mainframe}
  \includegraphics[width=8em]{img/Summit_(supercomputer)}
  \includegraphics[width=8em]{img/Gamecube-console}
  \includegraphics[width=8em]{img/ThinkCentre_S50}
  \includegraphics[width=8em]{img/LYF_WATER_2_Smartphone}
  {\fontsize{6}{7}\selectfont Source: \url{https://en.wikipedia.org/wiki/Computer}}
\end{frame}

\begin{frame}{What is a Computer?}
  \begin{block}<+->{Definition}
    A \textbf{computer} is a machine that is
    \begin{itemize}[<+->]
      \item programmable and executes a series of commands,
      \item processes input data,
      \item obtaining useful information,
      \item which is subsequently sent to output units.
    \end{itemize}
  \end{block}

  \begin{block}<+->{Components}
    \begin{description}[<+->]
      \item[Hardware] Physical structure (electronic circuits, cables, cabinet, keyboard, mouse, etc.).
      \item[Software] Intangible part (programs, data, information, documentation, etc.).
    \end{description}
  \end{block}
  {\fontsize{6}{7}\selectfont Source:
    \url{https://en.wikipedia.org/wiki/Computer}}
\end{frame}

\begin{frame}
  \frametitle{Physical Structure}
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/670px-Personal_computer,_exploded_5.svg}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{enumerate}
      \item Monitor.
      \item Motherboard (Main board).
      \item Microprocessor (CPU).
      \item RAM Memory.
      \item Expansion cards and slots.
      \item Power supply.
      \item Optical disc drive (CD; DVD; BD).
      \item Hard disk drive or Solid-state drive.
      \item Keyboard.
      \item Mouse.
      \end{enumerate}
    \end{column}
  \end{columns}
\end{frame}

\begin{frame}
  \frametitle{Computer Capacity and Performance}
  \begin{description}[<+->]
    \item[Number of Cores] Indicates how many CPUs it has (parallel
      processing). A modern personal computer can have 6 cores.
    \item[CPU Speed]
      The number of basic instructions per second.
    \item[Memory Capacity] \mbox{ }
      \begin{itemize}
        \item Internal Memory (RAM)
        \item Storage Space (Hard Drive, SSD)
      \end{itemize}
  \end{description}
\end{frame}

\begin{frame}
  \frametitle{CPU Speed}
  \begin{itemize}[<+->]
    \item Basic instructions, e.g., adding two numbers.
    \item How many basic instructions per second it is capable of
      executing.
    \item Speed: 1 Hz = 1 instruction per second.
    \item Apollo Guidance Computer: 1 core @ 2.048 MHz.
    \item Commodore 64 (1980s): 1 core @ 1 MHz.
    \item Intel Core i7: 6 cores @ 3.3 GHz. ($1\text{G} = 10^9$).
    \item El Capitan (Current top supercomputer): 1,051,392 cores @ 1.8 GHz.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Storage: Memory Magnitudes}
  \begin{center}
    \includegraphics[width=.3\hsize]{img/byte.png}
  \end{center}
  \begin{description}
    \item<2->[Kilobyte (KB)] $2^{10}\approx 10^3$. \onslide<8->{Don Quixote (book): 850 KB}
    \item<3->[Megabyte (MB)] $2^{20}\approx 10^6$. \onslide<9->{Photo: 3 MB (8Mpx). 1 CD: 800 MB}
    \item<4->[Gigabyte (GB)] $2^{30}\approx 10^9$. \onslide<10->{DVD: 4.7 GB. Wikipedia: 120 GB}
    \item<5->[Terabyte (TB)] $2^{40}\approx 10^{12}$. \onslide<11->{+200 DVDs. Facebook: 750 TB/day}
    \item<6->[Petabyte (PB)] $2^{50}\approx 10^{15}$. \onslide<12->{Netflix: 3.14 PB. Google Maps: 20 PB}
    \item<7->[Exabyte (EB)] $2^{60} \approx 10^{18}$. \onslide<13->{Google: 10 EB on disk}
    \item<14-> Zettabytes (ZB), Yottabytes (YB)...
  \end{description}
  \begin{center}
    \onslide<15->{\url{http://www.bluebulbprojects.com/MeasureOfThings/}\\ \url{http://www.internetlivestats.com/}}
  \end{center}
\end{frame}

\begin{frame}
  \frametitle{Memory Evolution}
  \begin{itemize}[<+->]
    \item Apollo Guidance Computer: 2 KB (RAM), 36 KB (ROM).
    \item Commodore 64: 64 KB (RAM), 16 KB (ROM).
    \item Modern PC: 32 GB RAM, 1 TB (Hard Drive/SSD).
  \end{itemize}
\end{frame}

\begin{frame}[allowframebreaks]
  \frametitle{Historical Perspective}

  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/Boulier1}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item More than 5,000 years ago.
      \item Addition, subtraction, multiplication, division, and square roots.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/The_Brahmi_numeral_system_and_its_descendants}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item Indo-Arabic numerals.
      \item Facilitated mathematical operations.
      \item Faster and more reliable.
      \end{itemize}
    \end{column}
  \end{columns}
  Number one story:
  \url{https://youtu.be/jrLQW1vQklE?si=Rv_RwWJzURBCMNpV}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/Muhammad_al-Juarismi.jpg}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item Muḥammad Al-Khwarizmi, Latinized as Algorithmi.
      \item 9th-century Persian mathematician.
      \item Father of Algebra.
      \item Precursor to modern algorithms.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/Arts_et_Metiers_Pascaline_dsc03869}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item The Pascaline.
      \item Blaise Pascal (at age 19), 17th Century.
      \item Mechanical addition using gear wheels.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/960px-Leibniz_binary_system_1697}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item Binary System.
      \item Leibniz, 17th Century.
      \item Influenced by ancient systems in India and China (I-Ching).
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/AnalyticalMachine_Babbage_London}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item Charles Babbage's Analytical Engine, 19th Century.
      \item Never fully built due to the technical complexity of the era.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.7\hsize]{img/Ada_Byron_daguerreotype_by_Antoine_Claudet_1843_or_1850}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item Ada Lovelace (Augusta Ada Byron).
      \item The world's first computer programmer.
      \item Wrote programs for Babbage's machine.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/Alan_turing_header}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item Mathematician, Father of Modern Computing.
      \item Cracked the Enigma (Nazi's encrypting machine, II World World) code with the Bombe machine.
      \item Convicted for his sexual orientation; pardoned decades after his death.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/Arquitectura_Von_Neumann}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item John von Neumann (1945).
      \item Defined the architecture used in current computers.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/Kilby_Circuit}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item The Integrated Circuit (IC).
      \item Jack S. Kilby, 1958.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/First_Computer_Bug}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item The first documented "Bug" was a literal moth.
      \item 1947: A hardware failure caused by an insect.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \centering
      ENIAC\\
      \vskip 1em
      \includegraphics[width=0.9\hsize]{img/ENIAC}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item 1945: First general-purpose programmable electronic computer.
      \item Turing Complete: Capable of solving any computable problem.
      \item Cost \$487,000 (approx. \$6.9 million today).
      \item Size: 2m x 1m x 30m. Weight: 20 Tons.
      \item Speed: 5 kHz.
      \item Storage: Punched cards. Output: Printer.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/tarjeta_perforada}
      \includegraphics[width=0.9\hsize]{img/lector_tarjeta_perforada}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item Each card represents a line of 80 characters.
      \item A program is a stack of these punched cards.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \centering
      IBM 360 (1964)\\
      \vskip 1em
      \includegraphics[width=0.9\hsize]{img/IBM_360}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item First large-scale commercial computers.
      \item Speed: 34.5 kHz. Memory: 8--64 KB.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  Languages of the 60s: COBOL, FORTRAN\\
  \vskip 1em
  \includegraphics[width=0.45\hsize]{img/COBOL}
  \hfill
  \includegraphics[width=0.45\hsize]{img/FORTRAN}

  \framebreak
  \centering
  The 1970s\\
  \begin{columns}[T]
    \begin{column}{0.5\hsize}
      \centering
      PDP-11 (Digital Equipment Corporation)\\
      \vskip 1em
      \includegraphics[width=0.95\hsize]{img/pdp_11.jpg}\\
    \end{column}
    \begin{column}{0.5\hsize}
      \centering
      \includegraphics[width=0.65\hsize]{img/unix.png}
      \includegraphics[width=0.55\hsize]{img/c.png}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/internet}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item ARPANET (1969): First 2 nodes between UCLA and SRI.
      \item TCP Protocol (1982): Global expansion.
      \item HTML (1990): First web browsers.
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \centering
      The First Personal Computers\\
      \vskip 1em
      \includegraphics[width=0.9\hsize]{img/ZX81}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item Sinclair ZX81 (1981).
      \item 1 KB RAM. Z80 CPU @ 3.25 MHz.
      \item Programs stored on cassette tapes.
      \item Cost: £69.95 (approx. €400 today).
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/pc}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item IBM Personal Computer.
      \item 16 KB RAM. Intel 8088 @ 4.77 MHz.
      \item Cost: \$1,565 (approx. €6,000 today).
      \item Floppy disk drives (160--320 KB).
      \end{itemize}
    \end{column}
  \end{columns}

  \framebreak
  \begin{columns}
    \begin{column}{0.5\hsize}
      \includegraphics[width=0.9\hsize]{img/iphone}
    \end{column}
    \begin{column}{0.5\hsize}
      \begin{itemize}
      \item Pocket Computing.
      \item 2007: First iPhone launched.
      \item 128 MB RAM. 4 GB Storage.
      \end{itemize}
    \end{column}
  \end{columns}

\end{frame}

\begin{frame}{What is Programming?}
  \begin{quote}
    Programming is the process of designing, writing, testing,
    debugging, and maintaining the source code of computer programs.
  \end{quote}

  \begin{itemize}
  \item \textbf{Algorithm:} A finite, ordered sequence of well-defined
    instructions that solves a problem.
  \item \textbf{Source Code:} The set of instructions written
    in a programming language.
  \item \textbf{Programming Language:} A formal language designed
    to communicate instructions to a machine.
  \end{itemize}
\end{frame}


\begin{frame}{Why Python?}
  \begin{itemize}
    \item \textbf{Easy to learn and read:} Clear and concise syntax.
    \item \textbf{Versatile:} Wide range of applications (Web, AI, Data Science, Automation, etc.).
    \item \textbf{Large community:} Extensive support and resources.
    \item \textbf{Multi-paradigm:} Supports Object-Oriented, Functional, and Structured programming.
    \item \textbf{Extensive libraries:} A rich ecosystem of modules.
  \end{itemize}
\end{frame}


\begin{frame}[fragile]{Your First Program: "Hello World"}
\begin{lstlisting}[language=Python]
print("Hello World")
  \end{lstlisting}

  \begin{itemize}
    \item The \texttt{print()} function is used to display text on the console.
    \item Text strings are enclosed in either double (") or single (') quotes.
  \end{itemize}
\end{frame}




\begin{frame}[fragile]{Comments}
  \begin{lstlisting}[language=Python]
# This is a single-line comment
print("Hello") # This is a comment at the end of a line

"""
This is a multi-line
comment (docstring).
It is used to explain blocks of code.
"""
print("World")
  \end{lstlisting}

  \begin{itemize}
    \item Comments are ignored by the Python interpreter.
    \item They help make the code more readable and understandable.
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Variables}
  \begin{lstlisting}[language=Python]
name = "Alice"
age = 30
height = 1.75
is_student = True

print(name)
print(age)
print(height)
print(is_student)
  \end{lstlisting}

  \begin{itemize}
    \item Variables are containers for storing data values.
    \item Python is dynamically typed: you do not need to declare the
      variable type.
  \end{itemize}
\end{frame}

\begin{frame}{Basic Data Types}
  \begin{itemize}
    \item \textbf{Integers (\texttt{int}):} Whole numbers, positive or
      negative (e.g., \texttt{10}, \texttt{-5}).
    \item \textbf{Floats (\texttt{float}):} Numbers with a decimal point
      (e.g., \texttt{3.14}, \texttt{-0.5}).
    \item \textbf{Strings (\texttt{str}):} Sequences of characters
      (e.g., \texttt{"Hello"}, \texttt{'Python'}).
    \item \textbf{Booleans (\texttt{bool}):} Truth values
      (\texttt{True}, \texttt{False}).
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Comparison Operators}
  \begin{lstlisting}[language=Python]
x = 10
y = 12

print(f"x == y: {x == y}")  # False
print(f"x != y: {x != y}")  # True
print(f"x > y: {x > y}")    # False
print(f"x < y: {x < y}")    # True
print(f"x >= y: {x >= y}")  # False
print(f"x <= y: {x <= y}")  # True
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Logical Operators}
  \begin{lstlisting}[language=Python]
p = True
q = False

print(f"p and q: {p and q}") # False
print(f"p or q: {p or q}")   # True
print(f"not p: {not p}")     # False
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]{Entrada de Datos}
  \begin{lstlisting}[language=Python]
nombre = input("Ingresa tu nombre: ")
edad_str = input("Ingresa tu edad: ")
edad = int(edad_str) # Convertir a entero

print(f"Hola, {nombre}. Tienes {edad} años.")
  \end{lstlisting}

  \begin{itemize}
  \item \texttt{input()} function reads a line from the user.
  \item It always returns a string (\texttt{str}).
  \item If we need another value type, you need to convert to the
    corresponding type
    (ej. \texttt{int()}, \texttt{float()}).
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{User Input}
  \begin{lstlisting}[language=Python]
name = input("Enter your name: ")
age_str = input("Enter your age: ")
age = int(age_str) # Convert to integer

print(f"Hello, {name}. You are {age} years old.")
  \end{lstlisting}

  \begin{itemize}
    \item The \texttt{input()} function reads a line of text from the user.
    \item It always returns a string (\texttt{str}).
    \item You must convert it to other data types if needed
      (e.g., \texttt{int()}, \texttt{float()}).
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Control Structures: \texttt{if}-\texttt{elif}-\texttt{else}}
  \begin{lstlisting}[language=Python]
temperature = 25

if temperature > 30:
    print("It is very hot.")
elif temperature > 20:
    print("The temperature is pleasant.")
else:
    print("It is cold.")
  \end{lstlisting}

  \begin{itemize}
    \item Allows executing different blocks of code based on conditions.
    \item Indentation is crucial in Python to define code blocks.
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Estructuras de Control: \texttt{while} Loop}
  \begin{lstlisting}[language=Python]
contador = 0
while contador < 5:
  print(f"Contador: {contador}")
  contador += 1 # contador = contador + 1
  \end{lstlisting}

  \begin{itemize}
  \item Repite un bloque de código mientras una condición sea
    verdadera.
  \item Es importante asegurarse de que la condición eventualmente
    se vuelva falsa para evitar bucles infinitos.
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Control Structures: \texttt{while} Loop}
  \begin{lstlisting}[language=Python]
counter = 0
while counter < 5:
    print(f"Counter: {counter}")
    counter += 1 # equivalent to counter = counter + 1
  \end{lstlisting}

  \begin{itemize}
    \item Repeats a block of code as long as a condition is true.
    \item It is important to ensure that the condition eventually
      becomes false to avoid infinite loops.
  \end{itemize}
\end{frame}


\begin{frame}[fragile]{Estructuras de Control: \texttt{for} Loop}
  \begin{lstlisting}[language=Python]
frutas = ["manzana", "banana", "cereza"]
for fruta in frutas:
  print(fruta)

for i in range(5): # i toma valores 0, 1, 2, 3, 4
  print(f"Número: {i}")
  \end{lstlisting}

  \begin{itemize}
  \item Itera sobre elementos de una secuencia (listas, cadenas,
    rangos, etc.).
  \item La función \texttt{range(n)} genera una secuencia de números
    desde 0 hasta n-1.
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Control Structures: \texttt{for} Loop}
  \begin{lstlisting}[language=Python]
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
    print(fruit)

for i in range(5): # i takes values 0, 1, 2, 3, 4
    print(f"Number: {i}")
  \end{lstlisting}

  \begin{itemize}
    \item Iterates over elements of a sequence (lists, strings,
      ranges, etc.).
    \item The \texttt{range(n)} function generates a sequence of numbers
      from 0 to n-1.
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Functions}
  \begin{lstlisting}[language=Python]
def greet(name):
    print(f"Hello, {name}!")

def add(a, b):
    return a + b

greet("Alice")
result = add(5, 3)
print(f"The sum is: {result}")
  \end{lstlisting}

  \begin{itemize}
    \item Functions are reusable blocks of code that perform a specific task.
    \item \texttt{def} is used to define a function.
    \item \texttt{return} is used to send back a value.
  \end{itemize}
\end{frame}


\begin{frame}[fragile]{Lists}
  \begin{lstlisting}[language=Python]
numbers = [1, 2, 3, 4, 5]
fruits = ["apple", "banana", "cherry"]

print(f"First fruit: {fruits[0]}") # apple
print(f"Last number: {numbers[-1]}") # 5

fruits.append("orange") # Add to the end
print(f"Fruits: {fruits}")

fruits[1] = "blueberry" # Modify an element
print(f"Modified fruits: {fruits}")

print(f"Length of fruits: {len(fruits)}")
  \end{lstlisting}

  \begin{itemize}
    \item Lists are ordered and mutable collections of items.
    \item They are defined using square brackets \texttt{[]}.
    \item Elements are accessed by index (starting at 0).
  \end{itemize}
\end{frame}


\begin{frame}[fragile]{Strings}
  \begin{lstlisting}[language=Python]
greeting = "Hello, "
name = "World"
message = greeting + name + "!" # Concatenation

print(message) # Hello, World!
print(f"Length: {len(message)}")

print(message.upper()) # HELLO, WORLD!
print(message.lower()) # hello, world!
print(message.replace("World", "Python")) # Hello, Python!
  \end{lstlisting}

  \begin{itemize}
    \item Strings are immutable.
    \item String methods can be used for manipulation (e.g.,
      \texttt{upper()}, \texttt{lower()}, \texttt{replace()}).
    \item f-strings (\texttt{f""}) are a convenient way to
      format strings.
  \end{itemize}
\end{frame}

\begin{frame}[fragile]{Modules and Packages}
  \begin{lstlisting}[language=Python]
import math
import random

print(f"PI: {math.pi}")
print(f"Square root of 16: {math.sqrt(16)}")

from random import randint
# Since we imported 'randint' directly, we don't need 'random.'
print(f"Random number between 1 and 10: {randint(1, 10)}")
  \end{lstlisting}

  \begin{itemize}
    \item Modules are Python files (\texttt{.py}) that contain
      functions, classes, and variables.

    \item They allow you to organize and reuse code.
    \item \texttt{import} is used to include modules.
    \item \texttt{from ... import ...} is used to import specific
      elements from a module.
  \end{itemize}
\end{frame}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% TeX-command-extra-options: "-shell-escape"
%%% End:

%  LocalWords:  granularidad
