Re: newbe question about Sting Comparison
- To: mathgroup at smc.vnet.net
- Subject: [mg107015] Re: newbe question about Sting Comparison
- From: "Chris Degnen" <degnen at cwgsy.net>
- Date: Sun, 31 Jan 2010 07:54:11 -0500 (EST)
- References: <hk3nsk$alp$1@smc.vnet.net>
If you check the output of
ans = Input["Would you like to play a game"]
you will see it is not a string.
You can check it by typing a space in front of the output.
E.g. here: _yes
Cast the input into string form like this:
ans = ToString[Input["Would you like to play a game"]]
> 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
>