So, I'm following the Python chapter in the Raspberry Pi User Guide, and have already run up against a problem.
Following Example 2 ( the calculator program), I've copied the code exactly as in the example, and on trying to run it I get a syntax error warning.
in the second line of the program:
print "Welcome to the program,", userName
IDLE highlights the second quote mark.
Now, as far as I can see, I've followed the example exactly so I've no idea why the above is a syntax error, and there isn't any trouble-shooting advice given in the example.
Can anyone explain this to me please?
Example program from Raspberry Pi user guide (solved)
9 posts
- Posts: 23
- Joined: Wed Dec 26, 2012 1:26 pm
- Location: Derbyshire
That is a Python v2 program, so you should be using IDLE, and not IDLE3.
Thanks for that. Now running it in IDLE, not IDLE3, and get another syntax error in the line:
print firstNumber, "minus", secondNumber, "equals", firstNumber - secondNumber
with the highlight on the second quote mark (i.e. the end of "minus").
The corresponding quote in the previous line ("added to") isn't highlighted as an error, so I really can't see the difference.
print firstNumber, "minus", secondNumber, "equals", firstNumber - secondNumber
with the highlight on the second quote mark (i.e. the end of "minus").
The corresponding quote in the previous line ("added to") isn't highlighted as an error, so I really can't see the difference.
- Posts: 23
- Joined: Wed Dec 26, 2012 1:26 pm
- Location: Derbyshire
Sometimes I get syntax errors which are the result of leaving something off a previous line, such as a comma, or close paren, quote, or the like. It would be most helpful if you could copy and paste all of your code and enclose it using the "Code" button so it keeps the formatting (indenting is critical in Python).
- Posts: 60
- Joined: Tue Jul 24, 2012 9:10 pm
- Location: Silicon Valley, CA
The only thing I can think of is that you mis-typed the comma as a full-stop. The line as you have it above is correct.
- Code: Select all
userName = raw_input("What is your name? ")
print "Welcome to the program,", userName
goAgain =1
while goAgain ==1:
firstNumber = int(raw_input("Type the first number: "))
secondNumber = int(raw_input("Type the second number: "))
print firstNumber, "added to", secondNumber, "equals", firstNumber + secondNumber
print firstNumber "minus", secondNumber, "equals", firstNumber - secondNumber
print firstNumber "multiplied by", secondNumber, "equals", firstNumber * secondNumber
goAgain = int(raw_input("Type 1 to enter more numbers or any other number to quit: "))
- Posts: 23
- Joined: Wed Dec 26, 2012 1:26 pm
- Location: Derbyshire
rurwin wrote:The only thing I can think of is that you mis-typed the comma as a full-stop. The line as you have it above is correct.
Checked that, definitely a comma.
- Posts: 23
- Joined: Wed Dec 26, 2012 1:26 pm
- Location: Derbyshire
The two commas after firstNumber are not typed as a full stop, but missing completely.
jojopi wrote:The two commas after firstNumber are not typed as a full stop, but missing completely.
Thanks, I need a proof-reader
The more I looked at it, the less likely I probably was to notice it.
- Posts: 23
- Joined: Wed Dec 26, 2012 1:26 pm
- Location: Derbyshire