Why does my compiler say invalid syntax then highlight...?
Chris
cwitts at gmail.com
Tue Mar 11 03:01:47 EDT 2008
On Mar 11, 5:44 am, Nathan Pinno <MadComputer... at gmail.com> wrote:
> Why does my compiler say invalid syntax and then highlight the
> quotation marks in the following code:
>
> # This program is to find primes.
> primes = []
> import math
> import gmpy
> while 1:
> run = int(raw_input("Do you want to calculate primes? 1 = yes and
> 2 = no. "))
> if run == 1:
> y = int(raw_input("What number do you want to use as the final
> number to calculate with? "))
> x = int(raw_input("What number do you want to start
> calculating primes from? "))
> while x < 2:
> print "Number must be at least 2 for math reasons."
> else:
> while x < y:
> prime = math.cos(gmpy.pi(0) * gmpy.fac((x-1)) / x)
> if prime < 0:
> primes.append(x)
> else:
> print x " is not prime. " # highlights the final "
> here
> x = x + 1
> print primes
> elif run == 2:
> break
> else:
> print "Sorry, not a choice. Please enter your choice again."
> print "Goodbye."
>
> How do I fix such an invalid syntax?
>
> TIA,
> Nathan Pinno
The reason that line is giving you a syntax error is because you have
no comma between your variable and the string. Same reason you can do
something like 'print a b c' but instead have to use 'print a, b, c'
More information about the Python-list
mailing list