[Tutor] why the error?
Timothy Wilson
wilson@visi.com
Tue, 30 May 2000 15:31:27 -0500 (CDT)
On Tue, 30 May 2000, Wesley J. Chun wrote:
> well, guess what. it should *not* have worked in the interpreter either.
> the problem with the code is here:
>
> > for j in range(2, sqrt(number)+1):
Isn't the reason that it worked in the interpreter because I was passing an
integer directly?
>>> isPrime(17)
17 is prime.
> the reason why you get a TypeError is because the sqrt()
> function expects a floating point number. you passed in
> a string. the string comes from raw_input():
>
> > number = raw_input("Which number? ")
>
> the raw_input() built-in function returns a raw string of
> what the user enters.
Of course. That makes complete sense.
> finally, i am not familiar with the "%i" directive for the
> string format operator:
>
> > print "%i is prime." % number
>
> do you mean "%d" for integer?
I didn't have any python docs handy at the time so I guessed. It works. Go
figure.
> hope this helps!!
Thanks very much.
-Tim
--
Tim Wilson | Visit Sibley online: | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN | | http://slashdot.org/
wilson@visi.com | <dtml-var pithy_quote> | http://linux.com/