I am having difficulty adding code fragment to my slides in beamer with listings package.

My code:


\title{My slies}
\author{Me }
\date{October 2020}

%slide number


\begin{frame}{Slide 1}

def LosScore(y_pred, y_test):
  mse = []
  for i in range(len(y_test)):
return mse




Runaway argument?

! Paragraph ended before \lst@next was complete.
<to be read again> 
l.27 \end{frame}
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
  • 5
    You need to pass the option fragile to the frame environment: \begin{frame}[fragile]{Slide 1}. – campa Oct 2 '20 at 12:46
  • Thanks, that works. – arilwan Oct 2 '20 at 14:11