Area calculator

"""
Area calculator
"""

print "Program is starting"

option = raw_input("ENter t or c:")

if option == "C":
  radius = float(raw_input("enter radius"))
  area = 3.14 * 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)
    
else:
  print "Invalid" %option
  
print ("the end")

https://www.codecademy.com/courses/learn-python/projects/area-calculator

can you please let me know what the error here?

the error is:

File "AreaCalculator.py", line 12                                          
    print "Area %f" % area                                                   
    ^                                                                        
IndentationError: unexpected indent

looking at line 11 and 12:

  area = 3.14 * radius**2
  	print "Area %f" % area 

we can indeed see the indent doesn’t match.

2 Likes

Hi, @web2730660785,

See the discussion, For code indentation, is a single tab equivalent to 2 spaces or 4 spaces?, then check all of your indentation. Note that the Codecademy Python content currently (July 21, 2019) uses two spaces for each level of indentation, and does not use tabs.

1 Like
"""
Area calculator
"""

print "Program is starting"

option = raw_input("ENter t or c:")

if option == "C":
  radius = float(raw_input("enter radius"))
  area = 3.14 * 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)
    
else:
  print "Invalid" %option
  
print ("the end")

$ python AreaCalculator.py
File “AreaCalculator.py”, line 17
area = 0.5 * base * height
^
IndentationError: unindent does not match any o
uter indentation level

same issue, i recommend reformating your code outside codecademy IDE

1 Like

What about resetting your tabs to 2 spaces per Tab? I have done this but is it best practices?

There are soft tabs (where pressing the tab key will insert spaces) and hard tabs (special tab character). I find soft tabs to more consistent. From what I know, the majority of developers seem to prefer soft tabs, but its a never ending discussion.

also, the python style guide (link) seems to recommend 4 spaces indention. This is language specific.

1 Like