The code doesn't work


I am doing the Area Calculator using Python, this is my code:

"""The program does calculate area
of a shape"""

print "calculator is starting up"

option = raw_input("Enter C for Circle or T for Triangle:  ")
option = option.upper()

if option == 'C':
  radius = float(raw_input("Enter radius: "))
  area = 3.14159 * radius**2  
  print "Area: %f" % area
  elif option == 'T':
  base = float(raw_input("Enter base: "))
  height = float(raw_input("Enter height: "))
  area = 0.5 * base * height
  print "Area: %f" % area
  print "Invalid Shape"

print "Existing the program"

I keep facing the following area:

  1. Indentation error, especially with the line after the “radius” under “if” function
  2. Invalid Syntax for elif function

I’m not sure why but would appreciate the help.


the indent within the lesson uses the tab character (hard tab), i would recommend indenting the code in an editor with soft tabs (tabs are converted to spaces), that works generally better


It keeps saying that “elif option == ‘T’:” is invalid syntax, and i’m not sure why.

I tried to copy paste from the Hint section, to see if it works, but it doesn’t.


Did you fix the indent? elif always has to be after if or another elif statement:

if condition:
   # do something
elif condition:
   # do something else


By ‘after’ we mean with matching indentation characteristics. When the if has four spaces, the elif and the else (as apply) must also be four spaces. Four, two, tab, it’s all the same to Python so long as it is consistent and not mixed. When in doubt, strip the indents and manually insert them. You know where the blocks are supposed to be.