Area Calculator

option = raw_input("Enter C for circle or T for Triangle: ")

if option == ‘C’ :
radius = float(raw_input (“Enter radius:”))
area = 3.14 * radius ** 2
print ‘The area of the circle with a radius of %s is %s’ %(radius, area)

elif option == ‘T’ :
base= float(raw_input(“Enter base:”))
height= float(raw_input(“Enter height:”))
area = 0.5baseheight
print ‘The are of a triangle with a base of %s and a height of %s is %s’ %(base, height, area)

The error that comes up:: Traceback (most recent call last):
File “”, line 9 in
if option == ‘C’ :
NameError: name ‘option’ is not defined

I have made line 9 bold in this question. Please help.

link to exercise

Whenever you post code you should format it as code. This is especially helpful with Python since indentation is extremely important. To format code, my preferred method is to type 3 back tics, skip a line, type 3 more back tics then paste your code on the line between them:

Paste code here

I ran your code, and once I fixed this line, it worked as expected:

area = 0.5baseheight  # should be: 0.5 * base * height

If you’re still having problems after correcting this line, please re-post your code.
Hope this helps!

1 Like