Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: newbe question about Sting Comparison

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107016] Re: [mg107010] newbe question about Sting Comparison
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Sun, 31 Jan 2010 07:59:04 -0500 (EST)
  • References: <201001311058.FAA10875@smc.vnet.net>

>From the documentation: "Input returns the expression it reads...". So, what
happens is that your variable <ans> is assigned <yes> (as a Mathematica
expression,  Symbol in this case), not "yes" (as a String). So, the  fix
would be to write

ans = ToString@Input["Would you like to play a game"];

Regards,
Leonid



On Sun, Jan 31, 2010 at 2:58 AM, Biff. Bartolemew <harrytuttle777 at mac.com>wrote:

> Hello,
>
> I hope someone can help me out, and not laugh to hard at my stupidity,
> but, I am trying write a little program
>
>
> playAGame[] := Module[
>     {car},
>     ans = Input["Would you like to play a game"];
>     Print[ans];
>     If[ans == "yes", Print["you answered yes"],
>         Print["you did not answer yes"]
>     ];
>     If[5 == 5, Print["You suck"], Print["You Rock"]];
>
>     ]
>
> The first If statement does not seem to be evaluated.
>
> Yet, if I type:
>   "yes"=="yes",   I get the answer I am looking for.
>
> It seems like the string comparison is acting different in the middle of
> the If statement.  Can someone tell me what I am doing wrong?
>
>
> -Thanks
>
>



  • Prev by Date: Re: newbe question about Sting Comparison
  • Next by Date: Re: Re: position of sequence of numbers in list
  • Previous by thread: newbe question about Sting Comparison
  • Next by thread: Re: newbe question about Sting Comparison