\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{geometry}
\geometry{margin=2.5cm}
\usepackage{xcolor}
\usepackage{tcolorbox}
\usepackage{booktabs}
\usepackage{hyperref}

\definecolor{seblue}{rgb}{0.0,0.28,0.67}

\title{\textcolor{seblue}{Exercise 1: Arithmetic Expression Calculator}\\[0.3em]
\large AISE501 -- AI in Software Engineering I}
\author{Dr.\ Florian Herzog}
\date{Spring Semester 2026}

\begin{document}
\maketitle

\section{Use Case}

A user enters an arithmetic expression as a text string, for example \texttt{"3 + 5 * 2"}.
The program evaluates the expression and prints the result.

The calculator must:
\begin{itemize}
    \item Support the four basic operations: \texttt{+}, \texttt{-}, \texttt{*}, \texttt{/}
    \item Respect standard operator precedence (\texttt{*} and \texttt{/} bind more tightly than \texttt{+} and \texttt{-})
    \item Support parentheses for grouping, e.g.\ \texttt{"(4 + 6) * 2"}
    \item Support decimal numbers, e.g.\ \texttt{"3.5 + 2.5"}
    \item Handle errors gracefully (division by zero, invalid characters, empty input)
    \item \textbf{Not} use Python's built-in \texttt{eval()} function
\end{itemize}

\section{Example Input / Output}

\begin{center}
\begin{tabular}{ll}
\toprule
\textbf{Input Expression} & \textbf{Expected Output} \\
\midrule
\texttt{3 + 5}              & \texttt{8}    \\
\texttt{10 - 2 * 3}         & \texttt{4}    \\
\texttt{(4 + 6) * 2}        & \texttt{20}   \\
\texttt{100 / (5 * 2)}      & \texttt{10}   \\
\texttt{3.5 + 2.5 * 4}      & \texttt{13.5} \\
\texttt{(1 + 2) * (3 + 4)}  & \texttt{21}   \\
\texttt{(empty)}             & Error message \\
\texttt{10 / 0}              & Error message \\
\texttt{abc + 1}             & Error message \\
\bottomrule
\end{tabular}
\end{center}

\section{Exercise}

Two implementations are provided:

\begin{enumerate}
    \item \textbf{\texttt{calculator\_bad.py}} -- A working but poorly written version that violates many clean code and PEP\,8 principles.
    \item \textbf{\texttt{calculator\_good.py}} -- A clean, well-structured version following PEP\,8 and clean code best practices.
\end{enumerate}

\subsection*{Tasks}

\begin{enumerate}
    \item Run both programs and verify they produce the same results.
    \item Read the bad version and list all clean code / PEP\,8 violations you can find.
    \item For each violation, explain which principle is broken and why it makes the code harder to read or maintain.
    \item Compare your list with the good version to see how each issue was resolved.
\end{enumerate}

\subsection*{Violations to Look For}

\begin{itemize}
    \item Unused imports
    \item Missing or misleading comments and docstrings
    \item Poor variable and function names (abbreviations, single letters)
    \item Inconsistent indentation and spacing
    \item Multiple statements on one line (semicolons)
    \item Missing whitespace around operators
    \item No proper error handling (bare \texttt{except}, printing instead of raising)
    \item Magic numbers and unclear logic flow
    \item Missing \texttt{if \_\_name\_\_ == "\_\_main\_\_"} guard
    \item No type clarity in function signatures
\end{itemize}

\end{document}
