-2

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!")
3
  • 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. Commented Oct 15, 2013 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. Commented Oct 15, 2013 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. Commented Oct 15, 2013 at 17:45

3 Answers 3

1
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.

4
  • again my apologies, please check the link as the colon is in the link sample with the error message. Commented Oct 15, 2013 at 4:24
  • @jitterbug Then it should run without problems. Try running the same code from a script file instead of console. Commented Oct 15, 2013 at 4:26
  • whats the difference between script file and console? i`m new to the IDLE, Commented Oct 15, 2013 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. Commented Oct 15, 2013 at 4:43
1

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.

1
  • sorry fixed that, the link will show I had that part correct, Commented Oct 15, 2013 at 4:24
0

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.