Click to See Complete Forum and Search --> : An extremely simple python question


PimpHolic
08-02-2001, 11:07 PM
here is the code


# Area calculation program

print "Welcome to the Area calculation program"
print "---------------------------------------"
print

# Print out the menu:
print "Please select a shape:"
print "1 Rectangle"
print "2 Circle"

# Get the user's choice:
shape = input("> ")

# Calculate the area:
if shape == 1:
height = input("Please enter the height: ")
width = input("Please enter the width: ")
area = height*width
print "The area is", area
else:
radius = input("Please enter the radius: ")
area = 3.14*(radius**2)
print "The area is", area


this is exaclty how it is on the website which contains the tutorial i am taking (as you can see im fairly new :) )

so my question is this
why will this not run in a terminal?

i type python area.py (area being the name of the file) and this is what i get


File "area.py", line 3
print "Welcome to the Area calculation program"
^
SyntaxError: invalid syntax


why am i getting this error? all the code seems to be fine to me..
and i wrote sort of a mini program or script like this and it worked fine

i am clueless, could someone explain what is going on?
thanks in advance

jemfinch
08-02-2001, 11:30 PM
$10 says you have an indentation problem. Make sure you're indented properly.

Jeremy

PimpHolic
08-03-2001, 01:00 AM
could ya explain that a bit more..?
i dont quite know what you mean..

jemfinch
08-03-2001, 01:36 AM
Python uses indentation to denote blocks. If your line isn't indented the same as the line above it, and the line above it isn't a line that starts a block (ie, if/elif/else/for/def/class) then you'll get a syntax error. I suspect that's your problem.

Jeremy

JasonC
08-03-2001, 07:14 AM
I typed the code exactly how you have it and it worked fine. Not sure why yours isn't working.