[Tex/LaTex] How to (use package exsheets to) make a exercise section at the end of each section or subsection like the following

countersexercisesexsheets

PS: exsheets isn't a must, all methods are welcome.

My document structure:

\documentclass{book}
\title{Introduction to Latex}
\author{Me}
\date{}
\begin{document}
    \chapter{first}
        \section{start}
            \subsection{install}
        \section{keyword}
    \chapter{second}
        \section{improve}
\end{document} 

I want that:
If a section have at least one subsection, then the exercise section is like the following.

enter image description here

If a section doesn't have any subsection, then the exercise section is like the following.
enter image description here

As I have shown, Exercises are counted in each chapter.
I am new to latex so that I read the documentation of exsheets and still don't know how to do it.

Best Answer

An approach using custom environments with custom lists. The exercises in the subsection have a different indentation so you can compare how is adjusted.

I am not sure if you want the exercises in a colored box, in this case, uncomment the three lines with the word tcolorbox for a start.

mwe

\documentclass{article}
\newcounter{qcounter}
%\usepackage{tcolorbox}
\title{The art of make something}
\date{}\author{}
\def\df{Lore ipsum dolor sit amet. } % You guessed! Just print dummy text

\newenvironment{questions}{%
%\begin{tcolorbox}
\bigskip\noindent{\bfseries\large Exercises section \thesection:}
\begin{list}
{{\bfseries Exercise \thesection.\arabic{qcounter}:}}{
\setlength\labelwidth{-1em}
\setlength\labelsep{1em}
\setlength\leftmargin{0cm}
\usecounter{qcounter}}}{\end{list}
%\end{tcolorbox}
} 

\newenvironment{subquestions}{
\bigskip\noindent{\bfseries Exercises section \thesubsection:}
\begin{list}
{{\bfseries Exercise \thesubsection.\arabic{qcounter}:}}{
\setlength\labelwidth{8em}
\setlength\labelsep{1em}
\setlength\leftmargin{12em}
\usecounter{qcounter}}}{\end{list}} 

\begin{document}
\maketitle


\section{General programming}

\df\df\df\df\df\par

\begin{questions}
\item \df\df\df\df
\item \df\df\df\df\df\df\df  
\item \df\df
\item \df
\end{questions}

\subsection{Phyton language}

\df\df\df\df\df\par

\begin{subquestions}
\item \df\df\df\df
\item \df\df\df\df
\item \df\df
\item \df
\end{subquestions}

\end{document}
Related Question