WeBWorK Main Forum

Scientific notation using contextAlternateDecimal

Scientific notation using contextAlternateDecimal

by Jonathan Desaulniers -
Number of replies: 0

Hi!

i'm having a problem trying to use the alternate decimal context with the scientific notation context. It doesn't seem to permit the use of the coma with the scientific notation. Is there a workaround for this to be possible.

Here is my code:

# DESCRIPTION

## KEYWORDS('Scientific Notation')


DOCUMENT();        

loadMacros(

  "PGstandard.pl",

  "MathObjects.pl",

  "contextScientificNotation.pl",

  "contextAlternateDecimal.pl",

);


TEXT(beginproblem());


BEGIN_TEXT

<style>

ol.alpha {

    counter-reset: alpha;

    display: table;

    padding:15px;  

}

ol li {

    display: table-row;

}

ol li span{

    display: table-cell;

    text-indent: 0px;

}

ol.alpha > li:before {

    margin-right: 0.5rem;

    font-weight: bold;

    counter-increment: alpha;

    content:counter(alpha, lower-alpha)") "

}

ol ul.a li{

    display:list-item;

    list-style-type: disc;

    list-style-position: outside;   

}

ol ul.a {

    padding-right: 20px;

}

</style>

END_TEXT


######################################

#  Setup


$decimalNumber1 = random(1000,9000,10)+random(1,9,1);

$exp1 = 3;


$decimalNumber2 = random(100000,900000,1000);

$exp2 = 5;


$exp31 = random(-1,-3);

$decimalNumber3 = (random(100000,900000,10)+random(1,9,1))*10**$exp31;

$exp3 = 5 + $exp31;


$exp41 = random(-6,-4);

$decimalNumber4 = (random(100,900,10)+random(1,9,1))*10**$exp41;

$exp4 = $exp41 + 2;

######################################

#  Main text


BEGIN_TEXT

Écrire les nombres suivants en notation scientifique. 

<button type="button" class="btn btn-link" data-toggle="collapse" data-target="#demo1">

<b> Notation </b>

</button>

<br>

<div id="demo1" class="collapse">

<table width="100%" border="1" cellspacing="0">

  <tr class="btn-primary">

    <td valign="top" align="left"  width="100%">

      <text style="color:white;padding-left:15px;">Notation de la réponse</text>

    </td>

  </tr>

    <tr style="background-color:#fdfdfe;">

      <td colspan="2"style="color:black;padding:0px;">

          <p align="left">


    <ul class="a">

  <li> Pour écrire un nombre décimal, vous devez utiliser le $BBOLD point $EBOLD au lieu de la virgule .

    </li>

    <li> Si l'exposant est négatif, vous ne devez pas utiliser les parenthèses. $BR

        Ex. \(10^{-1}\) s'écrit 10^-1

    </li>

</ul>


</p>         

      </td>

    </tr>

</table>

</div>


<div style="width:100%;"> 

  <ol class="alpha">

   <li>

    <span> 

    

    \( $decimalNumber1 \) =  \{ ans_rule(20) \} $exp1


</span>

   </li>

   <br>

  <li>

    <span>

 

 \( $decimalNumber2 \) =  \{ ans_rule(20) \} $exp2


</span>

   </li>

   <br>

  <li>

    <span>

 

 \( $decimalNumber3 \) =  \{ ans_rule(20) \} $exp3


</span>

   </li>

   <br>

  <li>

    <span>

 

 \( $decimalNumber4 \) =  \{ ans_rule(20) \} $exp4

 

 </span>

   </li>

   </div>

END_TEXT


######################################

#  Answers


Context("ScientificNotation");


Context()->operators->add("*" => Context()->operators->get("x"));

Context()->parens->add('(' => {close => ')', type => 'Real', removable => 1});


$answer1 = ScientificNotation($decimalNumber1);

$answer2 = ScientificNotation($decimalNumber2);

$answer3 = ScientificNotation($decimalNumber3);

$answer4 = ScientificNotation($decimalNumber4);


Context("AlternateDecimal");

Context()->flags->set(

  enterDecimals => "either",

  displayDecimals => ",",

);


ANS($answer1->cmp);

ANS($answer2->cmp);

ANS($answer3->cmp);

ANS($answer4->cmp);


$showPartialCorrectAnswers = 1;


######################################



COMMENT('MathObject version');

ENDDOCUMENT();


thanks!

Jonathan Desaulniers