I cann’t get mine to work even at this point

This is an app that calculates the area of a shape and displays the result
print "Your app is running"

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

if option == 'C':
	radius = float(raw_input("Input the radius here: "))
	area = 3.14 * radius ** 2
  print 'The area of your circle with radius %s is %s' % (radius, area)

I cann’t get mine to work even at this point.
I keep getting this error:

Any idea, how I can fix this?

It always thinks I entered C

Like it or not, you are going to have to master the art of writing (and following) code blocks without running into this common problem. The print statement indentation does not match that of the lines before it, but is also not unindented enough to logically follow the if statement.


Word of advice… Write the docstring after the program runs without errors, not before, otherwise it is just a mission statement. Same goes for print statements that are nothing more than window dressing.


I’m sorry, I don’t really get you. Do you mean I should adjust my indentation? because I’ve tried that before so all the commans after the If statement align and it still threw back an error. Also what is the docstring?


Yes. Look at it. There is a definite mismatch.

The lesson asks you to document the function you are writing as a first step. While I think this is a bit presumptuous of an writer to start with this declaration, the authot of this course thinks otherwise. I would write it only after I know the function works.

A docstring is one of two things. First, as documentation of the function, as in a description of what the function is both returning, and what it is accepting as arguments. Something to help readers understand the code. If the docstring is placed just inside the function before any other code, then Python has access to it through the .__doc__ attribute of the function object.

Second, as preformatted text that repeats on user inputs, such as a complex menu with options and descriptions that cannot be displayed on a single line. This sort of preformatting in a normal str object is rather more convoluted. Either are valid but authors tend to choose what mitigates their need with the greatest simplicity.


Thanks a lot!!! It worked.
Because it looked like this, after inserting 2 tabs, I assumed it was wrong.


Okay this is a great point, but I’d like to think the docstring gives the developer some sort of focus.
So he/she has to ensure the code does what it should do.


Then write it as such, and amend as you progress. Plan for success, but expect failure. That’s why scientists have hypothoses in front of their experiments and summaries afterward.

the goal is to have this function return the area of a circle with given radius

Amend as appropriate when the function succeeds. Set out your goal, achieve it, then document the result.


Great point. I’ll keep this in mind as I progress.


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