Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

'int' object has no attribute 'is_prime'

Hi ... I am wondering why this code is not working

for number in range(20,30):

`if number.is_prime():`

   `print number`

I got this error in Cocalc Error in lines 1-3 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 2, in <module> AttributeError: 'int' object has no attribute 'is_prime'

'int' object has no attribute 'is_prime'

Hi ... I am wondering why this code is not working

for number in range(20,30):

range(20,30):
`if number.is_prime():`
  if number.is_prime():
 `print number`
 print number

I got this error in Cocalc Error in lines 1-3 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 2, in <module> AttributeError: 'int' object has no attribute 'is_prime'

'int' object has no attribute 'is_prime'

Hi ... I am wondering why this code is not working

for number in range(20,30):
   if number.is_prime():
     print number

I got this error in Cocalc Cocalc

Error in lines 1-3
Traceback (most recent call last):
  File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 2, in <module>
AttributeError: 'int' object has no attribute 'is_prime''is_prime'

However, it works when I change the code to

for number in range(20,30):
    if is_prime(number):
        print number