Why do I get an invalid syntax error on the “i” in the for loop (python) [closed]












-3














I am learning to program with Python. Currently, I am trying to write a simple function that will check to see if a number that the user has entered is prime. The following portion of the function is throwing up an "invalid syntax" sign:



else:
For x in range(1,b**(1/2)):
If b%x==0:
print(str(b) + " is not prime")
break


"b" is a variable defined elsewhere in the function. It is an integer less than 500 that the user provides. I am getting an "invalid syntax" error pointing at the "x" in the "for x in range..." part of the code. I don't understand why this is the case and would greatly appreciate some insight into this problem.



If it helps, so far, the entire code looks as follows:



def check_prime():
b = input("Enter an integer less than 500: ")
if type(b)!='int':
print("Please enter an integer")
elif b > 500:
print ("Please choose a smaller number")
else:
For x in range(1,b**(1/2)):
If b%x==0:
print(str(b) + " is not prime")
break
print (str(b)+ " is prime")


I am aware that the function will not work exactly as I intend just yet, but I do not know how to move forward until I resolve the issue of the syntax error. Thank you, in advance, for your help.










share|improve this question













closed as off-topic by timgeb, Yunnosch, stovfl, roganjosh, gnat Nov 20 '18 at 21:18


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – timgeb, Yunnosch, stovfl, roganjosh

If this question can be reworded to fit the rules in the help center, please edit the question.













  • Use for and if instead of For and If
    – Filip Młynarski
    Nov 20 '18 at 19:08










  • For and If should be lower-case
    – JETM
    Nov 20 '18 at 19:08






  • 1




    Also, type(b) will never return 'int'. It may return int, however (Though in Python 3 input always returns a string).
    – Patrick Haugh
    Nov 20 '18 at 19:08












  • And b will always be string since that's what input function always returns
    – Filip Młynarski
    Nov 20 '18 at 19:09










  • Well I can't believe that I overlooked that. The change from upper to lower case sorted everything out. Also,@PatrickHaugh and @Filip Młynarski , the points about the input function returning a string are duly noted. You have saved me some trouble down the line. You all have my thanks.
    – Alex Stephanson
    Nov 20 '18 at 19:19
















-3














I am learning to program with Python. Currently, I am trying to write a simple function that will check to see if a number that the user has entered is prime. The following portion of the function is throwing up an "invalid syntax" sign:



else:
For x in range(1,b**(1/2)):
If b%x==0:
print(str(b) + " is not prime")
break


"b" is a variable defined elsewhere in the function. It is an integer less than 500 that the user provides. I am getting an "invalid syntax" error pointing at the "x" in the "for x in range..." part of the code. I don't understand why this is the case and would greatly appreciate some insight into this problem.



If it helps, so far, the entire code looks as follows:



def check_prime():
b = input("Enter an integer less than 500: ")
if type(b)!='int':
print("Please enter an integer")
elif b > 500:
print ("Please choose a smaller number")
else:
For x in range(1,b**(1/2)):
If b%x==0:
print(str(b) + " is not prime")
break
print (str(b)+ " is prime")


I am aware that the function will not work exactly as I intend just yet, but I do not know how to move forward until I resolve the issue of the syntax error. Thank you, in advance, for your help.










share|improve this question













closed as off-topic by timgeb, Yunnosch, stovfl, roganjosh, gnat Nov 20 '18 at 21:18


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – timgeb, Yunnosch, stovfl, roganjosh

If this question can be reworded to fit the rules in the help center, please edit the question.













  • Use for and if instead of For and If
    – Filip Młynarski
    Nov 20 '18 at 19:08










  • For and If should be lower-case
    – JETM
    Nov 20 '18 at 19:08






  • 1




    Also, type(b) will never return 'int'. It may return int, however (Though in Python 3 input always returns a string).
    – Patrick Haugh
    Nov 20 '18 at 19:08












  • And b will always be string since that's what input function always returns
    – Filip Młynarski
    Nov 20 '18 at 19:09










  • Well I can't believe that I overlooked that. The change from upper to lower case sorted everything out. Also,@PatrickHaugh and @Filip Młynarski , the points about the input function returning a string are duly noted. You have saved me some trouble down the line. You all have my thanks.
    – Alex Stephanson
    Nov 20 '18 at 19:19














-3












-3








-3







I am learning to program with Python. Currently, I am trying to write a simple function that will check to see if a number that the user has entered is prime. The following portion of the function is throwing up an "invalid syntax" sign:



else:
For x in range(1,b**(1/2)):
If b%x==0:
print(str(b) + " is not prime")
break


"b" is a variable defined elsewhere in the function. It is an integer less than 500 that the user provides. I am getting an "invalid syntax" error pointing at the "x" in the "for x in range..." part of the code. I don't understand why this is the case and would greatly appreciate some insight into this problem.



If it helps, so far, the entire code looks as follows:



def check_prime():
b = input("Enter an integer less than 500: ")
if type(b)!='int':
print("Please enter an integer")
elif b > 500:
print ("Please choose a smaller number")
else:
For x in range(1,b**(1/2)):
If b%x==0:
print(str(b) + " is not prime")
break
print (str(b)+ " is prime")


I am aware that the function will not work exactly as I intend just yet, but I do not know how to move forward until I resolve the issue of the syntax error. Thank you, in advance, for your help.










share|improve this question













I am learning to program with Python. Currently, I am trying to write a simple function that will check to see if a number that the user has entered is prime. The following portion of the function is throwing up an "invalid syntax" sign:



else:
For x in range(1,b**(1/2)):
If b%x==0:
print(str(b) + " is not prime")
break


"b" is a variable defined elsewhere in the function. It is an integer less than 500 that the user provides. I am getting an "invalid syntax" error pointing at the "x" in the "for x in range..." part of the code. I don't understand why this is the case and would greatly appreciate some insight into this problem.



If it helps, so far, the entire code looks as follows:



def check_prime():
b = input("Enter an integer less than 500: ")
if type(b)!='int':
print("Please enter an integer")
elif b > 500:
print ("Please choose a smaller number")
else:
For x in range(1,b**(1/2)):
If b%x==0:
print(str(b) + " is not prime")
break
print (str(b)+ " is prime")


I am aware that the function will not work exactly as I intend just yet, but I do not know how to move forward until I resolve the issue of the syntax error. Thank you, in advance, for your help.







python python-3.x for-loop syntax






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 19:06









Alex Stephanson

1




1




closed as off-topic by timgeb, Yunnosch, stovfl, roganjosh, gnat Nov 20 '18 at 21:18


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – timgeb, Yunnosch, stovfl, roganjosh

If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by timgeb, Yunnosch, stovfl, roganjosh, gnat Nov 20 '18 at 21:18


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – timgeb, Yunnosch, stovfl, roganjosh

If this question can be reworded to fit the rules in the help center, please edit the question.












  • Use for and if instead of For and If
    – Filip Młynarski
    Nov 20 '18 at 19:08










  • For and If should be lower-case
    – JETM
    Nov 20 '18 at 19:08






  • 1




    Also, type(b) will never return 'int'. It may return int, however (Though in Python 3 input always returns a string).
    – Patrick Haugh
    Nov 20 '18 at 19:08












  • And b will always be string since that's what input function always returns
    – Filip Młynarski
    Nov 20 '18 at 19:09










  • Well I can't believe that I overlooked that. The change from upper to lower case sorted everything out. Also,@PatrickHaugh and @Filip Młynarski , the points about the input function returning a string are duly noted. You have saved me some trouble down the line. You all have my thanks.
    – Alex Stephanson
    Nov 20 '18 at 19:19


















  • Use for and if instead of For and If
    – Filip Młynarski
    Nov 20 '18 at 19:08










  • For and If should be lower-case
    – JETM
    Nov 20 '18 at 19:08






  • 1




    Also, type(b) will never return 'int'. It may return int, however (Though in Python 3 input always returns a string).
    – Patrick Haugh
    Nov 20 '18 at 19:08












  • And b will always be string since that's what input function always returns
    – Filip Młynarski
    Nov 20 '18 at 19:09










  • Well I can't believe that I overlooked that. The change from upper to lower case sorted everything out. Also,@PatrickHaugh and @Filip Młynarski , the points about the input function returning a string are duly noted. You have saved me some trouble down the line. You all have my thanks.
    – Alex Stephanson
    Nov 20 '18 at 19:19
















Use for and if instead of For and If
– Filip Młynarski
Nov 20 '18 at 19:08




Use for and if instead of For and If
– Filip Młynarski
Nov 20 '18 at 19:08












For and If should be lower-case
– JETM
Nov 20 '18 at 19:08




For and If should be lower-case
– JETM
Nov 20 '18 at 19:08




1




1




Also, type(b) will never return 'int'. It may return int, however (Though in Python 3 input always returns a string).
– Patrick Haugh
Nov 20 '18 at 19:08






Also, type(b) will never return 'int'. It may return int, however (Though in Python 3 input always returns a string).
– Patrick Haugh
Nov 20 '18 at 19:08














And b will always be string since that's what input function always returns
– Filip Młynarski
Nov 20 '18 at 19:09




And b will always be string since that's what input function always returns
– Filip Młynarski
Nov 20 '18 at 19:09












Well I can't believe that I overlooked that. The change from upper to lower case sorted everything out. Also,@PatrickHaugh and @Filip Młynarski , the points about the input function returning a string are duly noted. You have saved me some trouble down the line. You all have my thanks.
– Alex Stephanson
Nov 20 '18 at 19:19




Well I can't believe that I overlooked that. The change from upper to lower case sorted everything out. Also,@PatrickHaugh and @Filip Młynarski , the points about the input function returning a string are duly noted. You have saved me some trouble down the line. You all have my thanks.
– Alex Stephanson
Nov 20 '18 at 19:19












2 Answers
2






active

oldest

votes


















2














Use for and if instead of For and IF. additionally, Python will give you an error if you skip the indentation






share|improve this answer





























    1














    'For' and 'If' should be 'for' and 'if'. Also, range takes two integers not a int and float.



    b=9
    for x in range(1,int(b**(1/2))):
    if b%x==0:
    print(str(b) + " is not prime")
    break





    share|improve this answer




























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      Use for and if instead of For and IF. additionally, Python will give you an error if you skip the indentation






      share|improve this answer


























        2














        Use for and if instead of For and IF. additionally, Python will give you an error if you skip the indentation






        share|improve this answer
























          2












          2








          2






          Use for and if instead of For and IF. additionally, Python will give you an error if you skip the indentation






          share|improve this answer












          Use for and if instead of For and IF. additionally, Python will give you an error if you skip the indentation







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 19:28









          Ahmed Abdelreheem

          212




          212

























              1














              'For' and 'If' should be 'for' and 'if'. Also, range takes two integers not a int and float.



              b=9
              for x in range(1,int(b**(1/2))):
              if b%x==0:
              print(str(b) + " is not prime")
              break





              share|improve this answer


























                1














                'For' and 'If' should be 'for' and 'if'. Also, range takes two integers not a int and float.



                b=9
                for x in range(1,int(b**(1/2))):
                if b%x==0:
                print(str(b) + " is not prime")
                break





                share|improve this answer
























                  1












                  1








                  1






                  'For' and 'If' should be 'for' and 'if'. Also, range takes two integers not a int and float.



                  b=9
                  for x in range(1,int(b**(1/2))):
                  if b%x==0:
                  print(str(b) + " is not prime")
                  break





                  share|improve this answer












                  'For' and 'If' should be 'for' and 'if'. Also, range takes two integers not a int and float.



                  b=9
                  for x in range(1,int(b**(1/2))):
                  if b%x==0:
                  print(str(b) + " is not prime")
                  break






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 '18 at 19:26









                  Victor 'Chris' Cabral

                  1,4391221




                  1,4391221















                      Popular posts from this blog

                      Costa Masnaga

                      Fotorealismo

                      Sidney Franklin