If you look at the file written out you will see there are no values, just \aaa and \bbb as you have prevented expansion with \unexpanded. Removing that enables the values to be written out, you should probably also not use non-immediate writes, but here I force expansion before the call to \foo
\documentclass[a4paper,11pt]{article} \usepackage{ProfLycee} \everymath{\displaystyle} \begin{document} \newwrite\myoutput \immediate\openout\myoutput=\jobname-corr.tex \newcommand{\foo}[2]{% \write\myoutput{{$\dfrac{#1}{#2}=\noexpand\ConversionFraction{#1/#2}$}} \write\myoutput{\unexpanded{\par \bigskip}} } \textbf{Exercice} : simplify each fraction. \par \bigskip \foreach \n in {1,2,...,5}{ \NbAlea{3}{50}{\aaa} \NbAlea{\aaa+1}{60}{\bbb} $\dfrac{\aaa}{\bbb} = \dfrac{\dots}{\dots}$ \par \bigskip \foo\expanded{\noexpand\foo{\aaa}{\bbb}} \par } \write\myoutput{\textbf{Correction} : \par } \newpage \immediate\closeout\myoutput \input{\jobname-corr.tex} \end{document} 
