473,419 Members | 4,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Why does my compiler say invalid syntax then highlight...?

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
Mar 11 '08 #1
6 6198
On Mar 10, 9:44*pm, Nathan Pinno <MadComputer...@gmail.comwrote:
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 thefinal
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
Try running this:

input = raw_input("Hello
world.")
Mar 11 '08 #2
On Mar 10, 9:44*pm, Nathan Pinno <MadComputer...@gmail.comwrote:
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 thefinal
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
Rather, try running this:

print 10 "Hello world."
Mar 11 '08 #3
I may have your problem:

if prime < 0:
primes.append(x)
else:
print x, "is not prime. " # highlights the final
"

you have to separate each output with a comma, so try adding one after
x.
Mar 11 '08 #4
On Mar 10, 10:44�pm, Nathan Pinno <MadComputer...@gmail.comwrote:
Why does my compiler say invalid syntax and then highlight the
quotation marks in the following code:

# This program is to find primes.
Needs work.

## Do you want to calculate primes? 1 = yes and 2 = no. 1
## What number do you want to use as the final number to calculate
with? 66
## What number do you want to start calculating primes from? 2
## 2 is not prime. False
## 3 is prime. True
## 4 is prime. False
## 5 is prime. True
## 6 is not prime. True
## 7 is prime. True
## 8 is not prime. True
## 9 is not prime. True
## 10 is not prime. True
## 11 is prime. True
## 12 is not prime. True
## 13 is prime. True
## 14 is not prime. True
## 15 is not prime. True
## 16 is not prime. True
## 17 is prime. True
## 18 is not prime. True
## 19 is prime. True
## 20 is not prime. True
## 21 is prime. False
## 22 is not prime. True
## 23 is prime. True
## 24 is prime. False
## 25 is prime. False
## 26 is not prime. True
## 27 is not prime. True
## 28 is not prime. True
## 29 is prime. True
## 30 is not prime. True
## 31 is not prime. False
## 32 is prime. False
## 33 is prime. False
## 34 is not prime. True
## 35 is prime. False
## 36 is not prime. True
## 37 is not prime. False
## 38 is not prime. True
## 39 is prime. False
## 40 is prime. False
## 41 is prime. True
## 42 is not prime. True
## 43 is not prime. False
## 44 is not prime. True
## 45 is prime. False
## 46 is not prime. True
## 47 is prime. True
## 48 is not prime. True
## 49 is not prime. True
## 50 is prime. False
## 51 is not prime. True
## 52 is not prime. True
## 53 is not prime. False
## 54 is not prime. True
## 55 is prime. False
## 56 is prime. False
## 57 is not prime. True
## 58 is not prime. True
## 59 is not prime. False
## 60 is prime. False
## 61 is prime. True
## 62 is not prime. True
## 63 is prime. False
## 64 is not prime. True
## 65 is prime. False
## Do you want to calculate primes? 1 = yes and 2 = no. 2
## Goodbye.
Mar 11 '08 #5
On Mar 11, 5:44*am, Nathan Pinno <MadComputer...@gmail.comwrote:
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 thefinal
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'
Mar 11 '08 #6
Mensanator <me********@aol.comwrote:
On Mar 10, 10:44‹¨«pm, Nathan Pinno <MadComputer...@gmail.comwrote:
>Why does my compiler say invalid syntax and then highlight the
quotation marks in the following code:

# This program is to find primes.

Needs work.
Be fair. The OP hadn't managed to figure out why the program wasn't
running, so you can't expect him to have got all the bugs out of the code
yet. And he only asked about the specific syntax error not the entire
solution to his homework.

My advice to Nathan would be:

1. If you get a weird syntax error that you don't understand try cutting
the code down to just the bit which generates the error.

2. Play around in the interactive interpreter to see what works and what
doesn't.

3. If you don't understand why the code doesn't work then get a stuffed
toy, cardboard cutout of a person, or the least technical member of your
family and explain to them in great detail exactly why the code must
(despite error messages to the contrary) be correct. Usually you'll spot
the problem half way through the explanation.

4. If you post to this list then post the full error message and traceback.
That way we don't have to guess which quotation marks are the problem.
Mar 11 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ray | last post by:
Python setup.py install No still getting "invalid syntax"
0
by: Mauricio Cruz Vidotto | last post by:
I'm planning to develop a .NET aplication using C# same Emacs Editor but I don't know how can I do syntax highlight. Any ideia about this? Tks Mauricio
4
by: Bradley Kite | last post by:
Hi all. I'm trying to diagnose/solve a problem with internet explorer, whereby sometimes the form submits, and other times IE produces an 'invalid syntax' error. First, I have a form, and...
0
by: Mark Phanides | last post by:
My ASP.NET application intermittantly (but always at same point) redirects to the 'Invalid Syntax Error' web page for some unknown reason. I've created a ASP.NET application written in VB.NET with...
5
by: DIBS | last post by:
I'm new to Python and I don't understand what I'm doing wrong. I'm running windows xp. In the command line window, I type: Python Sudoku.py and I get the response" SyntaxError: invalid...
2
by: py | last post by:
Hi, I am running python 2.4.2 on win xp pro. I have the WMI module from Tim Golden (http://tgolden.sc.sabren.com/python/wmi.html). I have some code which does this... MyScript.py...
10
by: ronrsr | last post by:
no matter where I place this imported file,the statement after it in the main program gets a syntax error, regardless of the syntax. I think I may have changed something in this file, but I'm...
7
by: alf | last post by:
Hi, I wonder why it is an invalid syntax: File "<stdin>", line 1 if 1: if 1: if 1: print 1 or
3
by: kakarot vegeta | last post by:
There 's an invalid syntax error but i don't know what's wrong with it. the error says Invalid syntax: print variation_string import itertools variations = itertools.product('ab',...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.