MathGroup Archive 2006

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

Search the Archive

Re: Beginner--Need to test and check real input values


Lian,

This works:
c = 0;
While[! (Head[c] ===
   Real && 0 < c < 0.9), c = Input["Give a positive real value to c
 less than 0.9"]]
Print["c= ", c]

RealQ is not a built-in function of Mathematica. But we may define it as:

RealQ := Head[#] === Real &;

On 11/23/06, abdou.oumaima at hotmail.com <abdou.oumaima at hotmail.com> wrote:
> Hello Math Group,
>
> I'm using While to control a flow of input values. I need to give a positive and real value to a variable, let's call it "c" . I write the code bellow but when I excute it, I can put a string value and can return it. How can I control that please.
>
> c = 0;
> While[! (RealQ[c] && 0 < c < 0.9), c = Input["Give a positive real value to c
>   less than 0.9"]]
> Print["c= ", c]
>
> Greetings.
> Lian.
>

-- 
Li Zhengji
-------------------------------------------------------------
If all you have is a hammer, everything is a nail.
-------------------------------------------------------------


  • Prev by Date: Re: Pythonika: Python in Mathematica
  • Next by Date: Re: Arithmetic Puzzle (so simple it's hard)
  • Previous by thread: Re: Beginner--Need to test and check real input values
  • Next by thread: Re: Beginner--Need to test and check real input values