Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Logic in Python Fully Functional

Indentation for print after the final call of our average function.

Why are we not giving four blank spaces after the call of average function in the last as the way we always do ?

def how_you_doing(): print("Travel Norway in Range Rover")

how_you_doing()

def oscar_issac_bluebook(name): if name.lower()== "nathan": print("Nathan designed Bluebook") else: print("{} is a cheat and {} stole all information".format(name, name))

oscar_issac_bluebook("nathan")

def average(num1, num2): return (num1 + num2) / 2

avg = average(10, 20) print(avg)

1 Answer

The avg = average() line of code is "outside" the average function.

The code that is indented are part of the function (in our case here) and tells what the function should do when it's called and the unindented code is the part where we actually call the function to use it.

I hope this helps. ~Alex

Please correct me if I am wrong ?

So, when we define the function, the code needs to be indented and when we call the function to use it, it's not necessary to indent it.

Well, you certainly can call a function inside of a function. But all of the code indented and put inside the function will be only run if another part of a program calls it.

If this continues to be strange, please review the videos about functions in Python. That is a very good way to refresh your mind ;)