[Tutor] unknown syntax error

boB Stepp robertvstepp at gmail.com
Thu Dec 15 11:34:00 EST 2016


On Sun, Dec 11, 2016 at 10:30 AM, oliver patterson <
oliverjamespatterson at hotmail.com> wrote:
> hey i dont know if this is the right place but i was just coding in idle
and kept getting this syntax error and i can not see m to fix it here is my
bit of code:

Yes, this is the right place.  Welcome to Tutor
​!

When you get some form of error, please copy and paste the full error
message in your email.  It is also usually helpful to state your version of
Python and operating system you are using.​


> my_age=14
> age=input("How old are you?:")
> print("type start()")
> def start():
>     print("hey")
>     if age == my_age:
>         print("i'm",age,"too")
>         else:
>             if age < 14:
>                 print(" i'm older that you i'm",my_age,":)")
>                 else:
>                     print("your older than me i'm",my_age,":(")
>

​When you use an if ... elif ... else construct, all of these need to be at
the same level of indentation and line up with each other.  That is:

if condition 1:
    insert condition 1 lines of code here
    ...

elif condition 2:
    condition 2 code here ...
    ...

else:
    code for else ...


In your given code, your "else" keyword should line up with the "if"
keyword above it.  Do you know about "elif"?  You might want to look that
up.  It would prove helpful in your example.

I'm curious as to how you will call your start() function.  Judging from
the "print("type start()")" line, I am wondering if you might have a
misconception.  But go ahead and plow forward and see what happens.  That
is how we learn.

HTH!


-- 
boB


More information about the Tutor mailing list