Outside function. What is this?

I’m on lesson ex23 in the LP3THW book and on line 10 where it starts with, return main XXXX I get an ‘outside function’ error. I have done a Google search on the term ‘outside function’ and also the whole line hoping to find someone that has had this same error. What little I can find, I don’t understand as it talks about more advanced code that only confuses me. I went through the list of Python questions on this board, and as I wrote this post I looked at the 'Your topic is similar to…" list and nothing is said about ‘outside function’. I know it has something to do with indentation, and I went into Notepad++ and set the preference to ‘tab as spaces’ in the preference setting. Nothing works. Please explain it slowly as I’m Not2smart.

Return statements can only be inside functions.

And indentation is the Python way of structuring your code. I suspect you have indented that line in such a way that the interpreter thinks it doesn’t belong to the function anymore. Hint: Make double sure the indent is exactly the same as in the line above. Also check that the whole if statement is correctly indented.

I hope this helps.

Yes, most likely what @florian said. You probably have this:

def myfunc():
    # code here then...
return X

But, you have to do this:

def myfunc():
    # code here then...
    return X

OK on the wrong indention. Because the book has part of that code on the next page, I didn’t notice the lining up wasn’t right. Now however I get one of those error messages about not having enough stuff to unpack in line two. I hate to say it, but I’m seriously considering dropping this book. I’m just not learning anything from it. Not2smart.

keep calm i’m even failed to write my first prog for two days if you wana achive something you have to aproach of never giveup.

@Not2smart - what’s your internet connection like and what time-zone are you in? If you like, I am happy to open a video call and talk through some things to try and unblock you or initially help you out to get you going.

Let me know if you feel it would be useful.

1 Like

:+1: what a great offer! :100:

Ahhhhhh, that’s interesting. Is this in the printed book or the PDF?