I decided to get creative with the area calculator and came up with my own two versions of it. One version follows the course somewhat closely while the other changes it up completely.

I’m getting two different values for the same equation when I run it. Why is that?

** AreaCalculator.py** (Follows the course somewhat closely)

```
"""
This program allows you to calculate the area
of a chosen shape. (Area Calculator)
(Takes a lot of work to extend and is semi-difficult to read)
"""
# Vars
pi = 3.14159
print 'Area calculator is starting.'
print 'The value of pi is %f. \n' % (pi)
def calc():
shape = raw_input('Circle, Triangle, or Exit: ')
if shape[0].lower() == 'c': # Circle
print 'You chose to calculate the area of a circle.'
r = float(raw_input('Radius: '))
area = pi * r**2
print "\nThe area of your circle is: %f" % (area)
elif shape[0].lower() == 't': # Triangle
print 'You chose to calculate the area of a triangle.'
b = float(raw_input('Base: '))
h = float(raw_input('Height: '))
area = 0.5 * b * h
print "\nThe area of your triangle is: %f" % (area)
elif shape[0].lower() == 'e': # Exit
exit(1)
else: # Foolishness
print 'Please type either "Circle", "C", "Triangle", or "T".\nDon\'t be a fool. \n\n'
calc()
calc()
```

When using the area calculator for a circle and using 6 as the radius, I get *113.097240*

When using the area calculator for a triangle and using 6 as the base and height, I get *18.000000*

** AreaCalculator2.py** (Changes everything)

```
"""
Revision of calculator using
functions the right way.
(Can be extended easily to have more math operations. Easy to read.)
"""
# Vars
pi = 3.14159
# Menu
def menu():
print 'Welcome to AreaCalculator2.py!'
print 'Would you like to find the area of a Circle(1) or a Triangle(2)?\n'
return int(raw_input('Circle(1), Triangle(2), or Quit(3)? '))
# Circle computation
def circle(r):
print '\nThe area of your circle is', pi * r**2
exit()
# Triangle computation
def triangle(b,h):
print 'The area of your triangle is', 0.5 * b * h
exit()
# Call everything
loop = 1
choice = 0
while loop == 1:
choice = menu()
if choice == 1:
print 'The value of pi is %f' % (pi)
circle(float(raw_input('Radius: ')))
elif choice == 2:
triangle(float(raw_input('Base: ')),(float(raw_input('Height: '))))
elif choice == 3:
loop = 0
print 'Thanks for using me!'
```

When using the area calculator for a circle and using 6 as the radius, I get *113.09724*

When using the area calculator for a triangle and using 6 as the base and height, I get *18.0*

I’m not sure why it’s truncating the extra 0s at the end when I’m using float(raw_input("x: ")) in both instances. Why does this happen?