Learning python SyntaxError: 'return' outside function - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Learning python SyntaxError: 'return' outside function (/thread-28779.html) |
Learning python SyntaxError: 'return' outside function - Grale1953 - Aug-03-2020 Here is my code: import string letters_guessed = ['x', 'i', 'k', 'p', 'r', 's', 'z', 'h', 'b'] alpha = string.ascii_lowercase available_letters = alpha def get_available_letters(letters_guessed): ''' letters_guessed: list (of letters), which letters have been guessed so far returns: string (of letters), comprised of letters that represents which letters have not yet been guessed. ''' for char in (alpha): print(char) if char in (letters_guessed): available_letters = available_letters.replace(char,'') print(available_letters)This code does what it should. It gives a printout of the alphabet minus letters guessed. ANYTIME I try to add a return statement ANYWHERE in this code I get either SyntaxError: 'return' outside function or IndentationError: unexpected indent. I have tried indenting everything in every manner I can manage. Please help. RE: Learning python SyntaxError: 'return' outside function - menator01 - Aug-03-2020 Please proper tags when posting code. RE: Learning python SyntaxError: 'return' outside function - Yoriz - Aug-03-2020 The lines from for char in (alpha): onwards are not indented into the function get_available_letters
RE: Learning python SyntaxError: 'return' outside function - buran - Aug-03-2020 Also, when debug error - always post the full traceback (in error tags) alongside the actual code that produce it (in python tags). (Aug-03-2020, 02:49 AM)Grale1953 Wrote: This code does what it should.This code (as is now) will produce error |