Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

Im doing a very simple piece of code, and it keeps generating a Syntax error, multiple statements found while compiling a single statement. I cant see what is wrong with my code ! :( , please look at the link as my code typed here may be correct but I cannot see the difference between it and that in the IDLE linked.

I`m attempting to convert the string '10' to an integer so the if statement works.

here is the screen shot. http://www.screencast.com/t/0zItqcn5P6d

age = '10'
converted_age = int(age)
if converted_age == 10:
    print("whats the best way to speak to a monster?")
    print("from as far away as possible!")
share|improve this question
    
Please paste the actual code that generates the error, and the actual error message, instead of code that works and a screenshot of different code and a vague description of an error message. –  abarnert Oct 15 '13 at 5:43
    
apologies I thought I did paste the same code, that ended up being the issue, I used a slightly different variable name for the if statement without realizing, im a newbie so this caught me out. I wont do that again hopefully. the reason I pasted a code shot instead of typing it was I new there was something there I "couldnt see" hence I screen capped it. –  jitterbug Oct 15 '13 at 11:46
    
The problem with screencaps is that if there's something you can't see, it won't be visible in the screencap either. And the problem with re-typing the code instead of copying and pasting it is that you can't re-type what you can't see. If you just copy the code from your editor, paste it here, select it, and click the "code" button (the {} icon), we're guaranteed to get exactly the code you had problems with (including things like tab/space mixing, non-printing characters, etc.). Anyway, it's not a big deal to not know the site before you ever used it; you'll learn. –  abarnert Oct 15 '13 at 17:45

3 Answers 3

up vote 0 down vote accepted
age = '10'
converted_age = int(age)
if converted_age == 10:
                      ^ Colon needed here.
    print("whats the best way to speak to a monster?")
    print("from as far away as possible!")

Console session:

>>> age = '10'
converted_age = int(age)
if converted_age == 10:
    print("whats the best way to speak to a monster?")
    print("from as far away as possible!")
whats the best way to speak to a monster?
from as far away as possible!

In your screen shot you use ConvertedAge to store the variable but you compare with converted_age, and this gives an error as covnerted_age is not defined.

share|improve this answer
    
again my apologies, please check the link as the colon is in the link sample with the error message. –  jitterbug Oct 15 '13 at 4:24
    
@jitterbug Then it should run without problems. Try running the same code from a script file instead of console. –  Games Brainiac Oct 15 '13 at 4:26
    
whats the difference between script file and console? i`m new to the IDLE, –  jitterbug Oct 15 '13 at 4:39
    
@jitterbug Well sometimes IDLE messes up because of indentation. A script file is a file that you run once after you write it, in IDLE, you are using a REPL, which is a "Read, Evaluate, Print, Loop", which means that your statements are computer in real time. In a script, you just write it, and run it. –  Games Brainiac Oct 15 '13 at 4:43
    
acknowledge ta! –  jitterbug Oct 15 '13 at 5:17

You are missing : after your if statement.

Well, I just executed

age = '10'
converted_age = int(age)
if converted_age == 10:
    print("whats the best way to speak to a monster?")
    print("from as far away as possible!")

with python2.7 and 3.0 and it seems ok to me. I can not reproduce it since you just said you have the same syntax above.

What is that orange line? Copy and paste exactly the same code above. Try it out.

share|improve this answer
    
sorry fixed that, the link will show I had that part correct, –  jitterbug Oct 15 '13 at 4:24

You screen cast shows an error because converted_age is undefined.

you have convertedAge = int(age) and you are trying to compare undefined converted_age.

share|improve this answer
    
hmm, thats what my book says but.. it lists the commands as I typed them. –  jitterbug Oct 15 '13 at 4:28
    
What you have here seems right, but check your screen cast link that you have posted. The two are not identical. –  meghamind Oct 15 '13 at 4:31
    
ohhhhh !!! >.< uhgg. would I see a truck if it hit me in teh face? .. thanks :) –  jitterbug Oct 15 '13 at 4:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.