Skip to content
Sign upLog in
← Back to Community
invalid syntax
Profile icon

import time
import random
from math import *

while (1 == 1):
while(1 == 1):
while(1 == 1):
while(1 == 1):
num1 = input("enter number: ")

num = float(num1) numby2 = float(num/int(2) numby3 = float(num/int(2) numby5 = float(num/5) numby7 = float(num/7) numfloat2 = float(numby2) numint2 = int(numby2) numfloat3 = float(numby3) numint3 = int(numby3) numfloat5 = float(numby5) numint5 = int(numby5) numfloat7 = float(numby7) numint7 = int(numby7) if numfloat2 == numint2: numdivby2 == True break else: numdivby2 == False break if numfloat3 == numint3: numdivby3 == True break else: numdivby2 == False break if numfloat5 == numint5: numdivby5 == True break else: numdivby5 == False break if numfloat7 == numint7: numdivby7 == True break else: numdivby7 == False break if num == 0 or num == 1: numdivby2 == False numdivby3 == False numdivby5 == False numdivby7 == False break elif num == 2 or num == 3 or num == 5 or num == 7: numdivby2 == False numdivby3 == False numdivby5 == False numdivby7 == False break if numdivby2 == False and numdivby3 == False and numdivby5 == False and numdivby7 == False: print(num + "is prime") break else: print(num + "is not prime") break

File "", line 13
numby3 = float(num/3)
SyntaxError: invalid syntax

i dont think that there should be an error can anyone help

thank you.

Profile icon
Profile icon

Right now, the error is that the programming cannot support prime numbers greater than 7 because you have not defined what you do with them. Consider using a different technique to calculate primes.
Here are some code critiques (I'm not trying to criticize, just help you improve).

  1. On line 3, you import 3 libraries which are not used in the program.
  2. Using 4 while loops is a very janky method so usually only use 1 while loop.
  3. The variable num is unnecessary, instead turn the input into a float num1 = float(input("enter number: "))
  4. Declaring all of those variables is really unnecessary and you should have to store different data types in different variables - just change the type of one variable. Instead of numfloat3 = float(numby3) and numint3 = int(numby3), use numby and int(numby3).
  5. On line 59, your if-elif-else statements lack an else, meaning they cannot cover numbers that don't satisfy the previous two conditions. This is the cause of the error I talked about at the beginning of this post.
    I hope you understood my feedback and good luck!