\documentclass[a4paper,french]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[margin=1cm]{geometry}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{listings}
\lstdefinestyle{mypython}{
language=Python,
tabsize=4,
numberstyle=\tiny,
columns=flexible,
showstringspaces=true,
literate=
{à}{{\`a}}1
{â}{{\^a}}1
{é}{{\'e}}1
{è}{{\`e}}1
{ê}{{\^e}}1
{ë}{{\"e}}1
{î}{{\^i}}1
{ô}{{\^o}}1
{ù}{{\`u}}1
{«}{{\og}}1
{»}{{\fg{}}}1
}
\usepackage[most]{tcolorbox}
\tcbset{
colback=black!05,
colframe=black!05,
sidebyside,
lower separated=false,
sharpish corners,
size=fbox,
sidebyside align=top seam,
boxrule=0pt,
}
\newtcblisting{mybox}[1][]{
colback=black!05,
colframe=black!05,
beforeafter skip balanced=0pt,
comment and listing,
comment outside listing,
sidebyside,
lower separated=false,
listing style=mypython,
beforeafter skip balanced=0pt,
top=0pt,
bottom=0pt,
sharpish corners,
size=fbox,
sidebyside align=top seam,
#1
}
\begin{document}
\begin{mybox}[comment={
\begin{enumerate}[series=myseries]
\item question 1...
\item question 2...
\item question 3...
\end{enumerate}
}]
def f(x):
y=x**2-x+3
return(y)
\end{mybox}
%
\begin{enumerate}[resume=myseries]
\item question 4 très très longue prenant toute la largeur de cette ligne ou presque ! ...
\end{enumerate}
%
\begin{mybox}[comment={
\begin{mybox}[listing options={language={[LaTeX]TeX}},
comment={
\begin{enumerate}[resume=myseries]
\item question 5...
\item question 6...
\item question 7...
\end{enumerate}
}]
\includegraphics[width=0.5\textwidth]{example-image}
\end{mybox}
\begin{tcolorbox}[colback=white,colframe=white,grow to left by=3pt]
\begin{enumerate}[resume=myseries]
\item question 5...
\item question 6...
\end{enumerate}
\tcblower
\includegraphics[width=0.5\textwidth]{example-image}
\end{tcolorbox}
\end{document}
![alt text][1]
[1]: https://texnique.fr/osqa/upfiles/Screen_Shot_2021-07-03_at_15.09.16.pnghttps://texnique.fr/osqa/upfiles/Screen_Shot_2021-07-03_at_18.04.38.png