I have a little problem with a variable and a string. I built a game with a panel that shows a random word,the player clicks "Yes" if he knows the meaning and clicks "No" otherwise. When the game ends a message is displayed.

Here's a part of my code:

l=10; *number of words you want to play with*

Row[{Button["Yes", click++], 
  Button["No"],Button["End game",m=StringJoin["You played with ",ToString[l]," "," words, and you know ", ToString[click],"words.\nThe Mathematica´s WordList has 39176 words, so you technically know ",ToString[p]," words."];Print[m]]}]

I got this message when I finish the game: enter image description here

The problem is how " p" is shown. I tried with "...ToString[NumberForm[per,5]]..." but didn't work.

I appreciate your help.


DONE. Adding "StandaForm" solved it.

  • 1
    $\begingroup$ does ToString[per, StandardForm] solve your issue? $\endgroup$
    – kglr
    Dec 1, 2020 at 0:37
  • $\begingroup$ Neither the code in your post nor the one in your image seem to work. Could you fix the code text? $\endgroup$
    – MarcoB
    Dec 1, 2020 at 0:41
  • $\begingroup$ you probably meant l=10; click=0; per:= 39176(click/l); ? (Note the definition of per using SetDelayed). $\endgroup$
    – kglr
    Dec 1, 2020 at 0:44
  • $\begingroup$ @MarcoB sorry, I already fixed it. $\endgroup$ Dec 1, 2020 at 0:57
  • $\begingroup$ @kglr Thanks!!! StandardForm worked, now there's a beatiful fraction instead. $\endgroup$ Dec 1, 2020 at 1:06

1 Answer 1


Define p using SetDelayed and use ToString[p, StandardForm]:

l = 10; click = 0;
p := 39176 (click/l);

Row[{Button["Yes", click++], Button["No"], 
  Button["End game", 
   m = StringJoin["You played with ", ToString[l], " ", 
     " words, and you know ", ToString[click], 
     " words.\nThe Mathematica\.b4s WordList has 39176 words, so you
   technically know ", ToString[p, StandardForm], " words."]; Print[m]]}]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.