Re: newbe question about Sting Comparison

• To: mathgroup at smc.vnet.net
• Subject: [mg107019] Re: [mg107010] newbe question about Sting Comparison
• From: "David Park" <djmpark at comcast.net>
• Date: Sun, 31 Jan 2010 08:18:49 -0500 (EST)
• References: <5875509.1264936173670.JavaMail.root@n11>

```Not stupid at all!

Note first that there is a difference between a String "no" and a Symbol no.
In the Input box you would have to type the quote marks.

Note second that there is a difference between Equal "==" and SameQ "===".
Equal will remain unevaluated if it is of the form no == "yes" because it is
not known what value no might have and Mathematica doesn't know whether they
are equal. Try ans === "yes" and it will evaluate.

You could also use the third argument of If, or you could use TrueQ. Look up
If, Equal, SameQ and TrueQ in Help.

David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/

From: Biff. Bartolemew [mailto:harrytuttle777 at mac.com]

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: Re: position of sequence of numbers in
• Previous by thread: Re: newbe question about Sting Comparison
• Next by thread: Partition prime list into equal k sublists. How to write code for