Example program from Raspberry Pi user guide (solved)


9 posts
by shifty1966 » Thu Jan 17, 2013 3:16 pm
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?
Posts: 23
Joined: Wed Dec 26, 2012 1:26 pm
Location: Derbyshire
by rurwin » Thu Jan 17, 2013 3:36 pm
That is a Python v2 program, so you should be using IDLE, and not IDLE3.
User avatar
Forum Moderator
Forum Moderator
Posts: 2946
Joined: Mon Jan 09, 2012 3:16 pm
by shifty1966 » Thu Jan 17, 2013 4:00 pm
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.
Posts: 23
Joined: Wed Dec 26, 2012 1:26 pm
Location: Derbyshire
by Digital Larry » Thu Jan 17, 2013 4:05 pm
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: 62
Joined: Tue Jul 24, 2012 9:10 pm
Location: Silicon Valley, CA
by rurwin » Thu Jan 17, 2013 4:07 pm
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.
User avatar
Forum Moderator
Forum Moderator
Posts: 2946
Joined: Mon Jan 09, 2012 3:16 pm
by shifty1966 » Thu Jan 17, 2013 4:21 pm
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
by shifty1966 » Thu Jan 17, 2013 4:22 pm
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
by jojopi » Thu Jan 17, 2013 4:26 pm
The two commas after firstNumber are not typed as a full stop, but missing completely.
User avatar
Posts: 2131
Joined: Tue Oct 11, 2011 8:38 pm
by shifty1966 » Thu Jan 17, 2013 4:29 pm
jojopi wrote:The two commas after firstNumber are not typed as a full stop, but missing completely.


Thanks, I need a proof-reader :lol:

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