Area Calculator _ Error line 11

Hi everyone,

The last hour I’ve been unable to find the mistake the terminal is pointing out, while trying to test out the validity of the first half of the Area Calculator exercise.

“”"
Area Calculator
“”"

print ‘Calculation in action!’

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

if option == ‘C’ or option == ‘Circle’:
area = 3.14 * radius ** 2
print ‘Area is %s’ % area

1 Like

Were we instructed to use 3.14 or pi?

``from math import pi``
1 Like

Apparently they have changed the instructions into a more streamlined exercise.

1 Like

1 Like
2 Likes

This is a free form project so no lesson checker

I would reduce the inputs to just `C` or `T` and accept both lower and upper case.

``````if option.lower in 'ct':
``````

For greater precision use the PI constant,

``````from math import pi
``````

If you use a float to multiply, the input does not need to be cast to float. Let the user input anything they wish.

``````print ‘Area is %s’ % area
``````

is old school. Suggest use `.format` or an f-string (Python 3.6 or higher).

https://realpython.com/python-f-strings/

2 Likes

@mtf thanks a lot for your time & the help.

I followed your suggestions to: from math import pi, reduced C,T inputs in lower.(), erased the float cast and used f-string method instead of %s,

but unfortunately it’s still reflecting the same error in line_11: area = pi * radius ** 2

Please post your revised code and we can test it. I don’t think the LE is 3.6 or higher. May have to revert to `str.format()`.

“”"
Area Calculator
“”"
from math import pi
print ‘Calculation in action!’

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

if (option.lower()) == ‘C’:
area = pi * radius ** 2
print f"Area is {area}"

#I also tried “Area is %f” %area

`````` if option.lower() == 'c':
``````

Aside

If you want it to be obvious that `pi` is a constant,

``````>>> from math import pi as PI
>>> PI
3.141592653589793
>>>
``````
1 Like

Thanks, I corrected it, but still… line_11 is doomed!

I don’t think you can use f-strings in the LE. Use str.format(), instead.

Redo all your indentaion using spaces, 2 or 4, but 4 are more obvious.

``````\$ python AreaCalculator.py
2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609]
Calculator is starting on 18/12/2018 at 23:57
Enter C for Circle or T for Triangle:c
The pie is baking...
The area is 3.14.
Don't forget to include the correct units!
Exiting...
\$
``````
1 Like

Ok, after I redid the identations it worked, we’ve made some progress:

Tried these 2 scenarios and in both I get an error regarding the exponentiation **

My bad… The input is a string that needs to be cast to a float. Fifty lashes with a wet noodle.

1 Like

Haha no worries, let me correct it real quick.

Update: Wooooohooooo!!! It worked!

1 Like

One last point… If we want to permit the user to type,

``````CIRCLE
``````

we can by zeroing in on the first character.

``if option[0].lower() == 'c':``
1 Like

Good point!

Thanks again for the help, very much appreciated.

It’s my 1st week learning Python and it’s been exciting with all the support. Looking forward to reach a more advanced level and start asking the “real” questions

All questions are real (as pertains to lessons and code in general) from where I stand. The really tough ones are more the challenge to answer. Keep up the groove and you’ll meet some experts in the tougher tracks.

1 Like

I really cant find my error here in my code in the elif conditional can someone please help point out my mistake ??

The print statements in each branch need to match the indentation of the line(s) that precede them.

1 Like