Indentation excercise

#1 i dont get this at all


Ok so on Lesson 6.) Whitespace Means Right Space you are learning about one of the most important concepts of basic coding in python: spacing or indention. As you learned in the lesson Whitespace: In Python, whitespace is used to structure code. Whitespace is important, so you have to be careful with how you use it. I like to think of whitespace as the "dead space" between your code lines. In this lesson you are correcting the spacing or whitespace of the code given to you. The code you have been given is this:

def spam():
eggs = 12
return eggs
print spam()

Now, to the just a casual glance, it might look fine. However, def spam() is a function. eggs = 12 and return eggs is under that function. Therefore, they must be spaced accordingly. What is the correct spacing for lines of code inside a function? One tab over. Please note this is just for basic function spacing. Now notice as well that the print statement is not apart of the function def spam(). It is its own separate thing and therefore doesn't need to be spaced. Your code should end up looking like this:

def spam(): //this is a function so things under it will need to be spaced
-------> eggs = 12 //spaced over one tab
------->return eggs //same here
print spam() //no space needed


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