Python Forum
Learning python SyntaxError: 'return' outside function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Learning python SyntaxError: 'return' outside function
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):
    if char in (letters_guessed):
        available_letters = available_letters.replace(char,'')
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.
Please proper tags when posting code.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
Gaming Collection
The lines from for char in (alpha): onwards are not indented into the function get_available_letters
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to invoke a function with return statement in list comprehension? maiya 4 313 Jul-17-2021, 04:30 PM
Last Post: maiya
Sad SyntaxError: from simple python example file from mind-monitor code (muse 2) warmcupoftea 4 212 Jul-16-2021, 02:51 PM
Last Post: warmcupoftea
  Function - Return multiple values tester_V 10 816 Jun-02-2021, 05:34 AM
Last Post: tester_V
  Question on None function in a machine learning algorithm Livingstone1337 1 510 Mar-17-2021, 10:12 PM
Last Post: supuflounder
  Get return value from a threaded function Reverend_Jim 3 675 Mar-12-2021, 03:44 AM
Last Post: Reverend_Jim
  Return not exiting function?? rudihammad 3 738 Dec-01-2020, 07:11 PM
Last Post: bowlofred
  "SyntaxError: invalid syntax" running code in Doing Math With Python b saucerdesigner 2 645 Nov-03-2020, 04:23 PM
Last Post: saucerdesigner
  Why does my function return None? vg100h 3 582 Oct-29-2020, 06:17 AM
Last Post: vg100h
  how to keep a Popen instance existant in a function return? Skaperen 7 903 Sep-17-2020, 07:10 PM
Last Post: Skaperen
  Function will not return variable that I think is defined Oldman45 6 1,094 Aug-18-2020, 08:50 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020