Python 2.7: example of using % operator

Trabla: Python 2.7: example of using % operator


Solving:

def renderView(self, style):
        """
        Returns an XHTML string for viewing this block
        """
        html = """

        <script type='text/javascript'>

            function calcScore%(idevice_id)s()
            {
                computeTime();  // the student has stopped here.

                var score = 0;
                var q_num = %(questions_number)s;
               
                document.getElementById("quizForm%(idevice_id)s").submitanswers.disabled = true; //disable submit button

                doLMSSetValue( "cmi.core.score.raw", score+"" );
                doLMSSetValue( "cmi.core.score.max", "100" );
                doLMSSetValue( "cmi.core.lesson_status", "passed" );
                doLMSSetValue( "cmi.core.exit", "" );
                doLMSSetValue( 'nav.event', 'continue' );
                doLMSCommit();
                doLMSFinish();

            }

        </script>

        """ % {
                'idevice_id': self.idevice.id
            ,   'questions_number': str(len(self.questionElements))
        }

        return html

No comments:

Post a Comment