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 StephansonAlex 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 AbdelreheemAhmed 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' CabralVictor 'Chris' Cabral

                  1,5201222




                  1,5201222















                      Popular posts from this blog

                      鏡平學校

                      ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                      Guess what letter conforming each word