1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What am I doing wrong?

Discussion in 'Scripting & Programming' started by OceanPacific, Mar 11, 2008.

  1. OceanPacific

    OceanPacific Byte Poster

    140
    1
    22
    Im typing this into python:

    n = input("Number? ")
    if n < 0:
    print "The absolute value of" ,n,"is",-n
    else:
    print "The absolulte value of",n,"is",n


    And its giving me a syntax error on "Else"??? Im doing exactly like the guidebook says. Any thoughts?
     
    WIP: N+, A+
  2. tripwire45
    Honorary Member

    tripwire45 Zettabyte Poster

    13,493
    179
    287
    Indentation error. "else" can't be indented. Here's what I did to make it work for me:
    Code:
    n = input("Number? ")
    if n < 0:
         print "The absolute value of" ,n,"is",-n
    else:
         print "The absolute value of",n,"is",n
    Python is sensitive to indentation. Tell me, are you learning from "Non-Programmers Tutorial For Python"? I had the identical exercise when studying from this source. Hope this helps. :)
     
    Certifications: A+ and Network+
  3. OceanPacific

    OceanPacific Byte Poster

    140
    1
    22

    Awesome, thanks Tripwire!

    Yes, I am learning from that guide. So far so good, though I have caught a few small mistakes, but its a free publication so you cant complain too much.

    I printed the PDF out at work and bound it so its like a real book!
     
    WIP: N+, A+

Share This Page

Loading...