My code doesn't work. Indent problem?


#1

Hi everyone! I am trying to do the AreaCalculator project but for some reason I keep getting indent errors. I just don't understand what I'm doing wrong. Any help will be appreciated.

"""
This program allows users to calculate the area of circles and triangles.
"""

from math import pi
from time import sleep
from datetime import datetime
now = datetime.now()

print "calculator starting up!"
print "current time: %s/%s/%s %s:%s" % (now.month, now.day, now.year, now.hour, now.minute)

sleep(1)

hint = "Don't forget to include the correct units! \nExitting..."

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

if option == "C":
    radius = float(raw_input("Input circle radius:"))
    circle_area = pi*radius**2
    print "The pie is baking..."
    sleep(1)
    print ("Circle Area: %.2f \n%s" % (circle_area, hint))

    elif option == "T":
        base = float(raw_input("Input triangle base:"))
  	height = float(raw_input("Input triangle height:"))
  	triangle_area = (0.5)*base*height
	print "Uni Bi Tri..."
	sleep(1)
	print ("Triangle Area: %.2f \n%s" % (triangle_area, hint))

else:
  	print "False inputs entered; program exiting"


#2

Your elif needs to align with your if statement. As written, the elif is inside the if statement.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.