[Tutor] why the error?
Timothy Wilson
wilson@visi.com
Tue, 30 May 2000 14:41:29 -0500 (CDT)
Hi everyone,
I've been working on some simple python programs, and I'm running into some
differences between the code I create in the interpretor and what's in a
text file. An example:
I wrote a little function that determines whether a given number is prime or
not. (I'm pretty sure the algorithm is correct.)
--snip--
from math import *
def isPrime(number):
for j in range(2, sqrt(number)+1):
if number % j == 0:
return 0
return 1
if __name__ == '__main__':
number = raw_input("Which number? ")
if isPrime(number):
print "%i is prime." % number
print "%i is not prime." % number
--snip--
This code seems to work perfectly when imported in the interpretor. When I
run it by typing 'python prime.py', I get:
[wilsont@galileo python]$ python prime.py
Which number? 11
Traceback (innermost last):
File "prime.py", line 15, in ?
if isPrime(number):
File "prime.py", line 8, in isPrime
for j in range(2, sqrt(number)+1):
TypeError: illegal argument type for built-in operation
Any hints? Why the difference?
-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/