Help with the course


#1

Hey

I’ve started with the python course here in the website and I’ve encountered I cant pass.

It’s the one with writing the program to calculate the area of a circle or triangle.

print “The program is now running…”


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 is %s” % (area)

I made a bold in order to show where the arrow point abut the problem
This is the code I wrote and the problem it says is that:
indentationerror unindent does not match any outer indentation level

please help with it… I watched the video and can’t seem to understand it.

Thank you!


#2

please post your code with format:

How do I format code in my posts?

this will preserve the indent(ion), which is critical if you have an indentionerror


#4

print "The program is now running..."
\
\
option = raw_input("Enter C for Circle or T for Triangle: ")

if option == "C":
	radius = float(raw_input("Enter radius: "))
  area = 3.14159 * radius**2
  print " The area of the Circle is %s" % (area)


#5

looking at the code:

        radius = float(raw_input("Enter radius: "))
   area = 3.14159 * radius**2

the indent error is pretty self explanatory. These two lines should have matching indent. Clearly they do not


#6

in the code they are all lined up
I kept two spaces

print "The program is now running..."
\
\
option = raw_input("Enter C for Circle or T for Triangle: ")

if option == "C":
   radius = float(raw_input("Enter radius: "))
  area = 3.14159 * radius**2
  print " The area of the Circle is %s" % (area

#7

i dont understand why it shows it like that


#8

don’t know that either, but copy pasting the code and applying format should preserve indention. So not much i can do here, ensuring your forum post is right is something you have to do, i can’t do it for you :wink:

the indent still isn’t a match:

   radius = float(raw_input("Enter radius: "))
  area = 3.14159 * radius**2

still one space difference.

Its annoying when i tell you your indent is off, and you come back with the same issue, but only with less spaces difference this time, its still the same issue i told you to fix


#9

I’ve deleted the spaces and did it again using the TAB key, and it worked.
Is there a difference whether I use the space key or the TAB key?


#10

that depends on the settings of the text-editor used, there are two kind of tabs. soft tabs and hard tabs

hard tabs insert a tab character
soft tabs insert spaces when the tab key is pressed

so if soft tab (which is generally preferred) is used, pressing the tab key will just insert spaces, but it inserts two/four/six spaces at once, again, depending on the editor settings

i worked with django for a while (python web framework), which means i used html and python at the same time, i configured the editor to use soft tabs, however, for html is set the soft tab to insert two spaces while for python i set the soft tab to insert four spaces. And yes, this is possible with most editors

changing these settings in codecademy is unfortunately not possible.


#11

Another question regarding this exercise, how come we use the same variable “area” in the if section and in the elif section? how does python does not mix between the two? shouldn’t it be two different variables?


#12

only one of the sections will execute (depending on what the user enters), so it isn’t a problem