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
else:
print "Invalid Shape"
print "Existing the program"
I keep facing the following area:
Indentation error, especially with the line after the “radius” under “if” function
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
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.