0

I've been trying to get this to work for a while, but can't figure out how it works. The things I read through on here didn't seem to be similar enough to what I'm trying to do.

I'm basically just trying to make an external function print a variable that's inside a class, but it tells me that "en" and "se" aren't defined. I get why this is, but how do you make it understand that you're trying to print the variable that's defined inside the class?

Also, bonus question, how do you actually make a function run? When I place the langchoice input inside a function either inside or outside the class, it just gets skipped. Hence why it's on its own in my example.

That's all I can do to describe my issue for now, but if you have any questions about it I'll do my best to provide more information.

class ChooseLanguage(object):

def English(self, lang):
    self.lang = lang
    en = ChooseLanguage("This is English")

def Swedish(self, lang):
    self.lang = lang
    se = ChooseLanguage("This is Swedish")

langchoice = input("What language do you prefer? English or Swedish?\n> ")
if langchoice == "English":
    print(en.lang(English))
elif langchoice == "Swedish":
    print(se.lang(Swedish))
else:
    print("nope")
maa
  • 5
  • 4
  • 4
    I know Stack Overflow makes indentation difficult, but with Python, you have to do it exactly right, or else we can't tell what's going on in your code. This is especially important for this question, because we need to know the exact scope of your variables to understand what you're trying to do and what the solution might be. – luther Nov 15 '17 at 17:34
  • You should look through [the Python Tutorial](https://docs.python.org/3/tutorial/index.html), especially part 9. What is this class supposed to represent? – Patrick Haugh Nov 15 '17 at 17:35
  • Fix your indention, right now `ChooseLanguage` is empty. –  Nov 15 '17 at 18:26
  • Dorian, thanks, it actually does look very similar to mine. luther, yep, I did do the indentation, for some reason it doesn't show correctly here. Patrick Haugh, thanks, that might be useful to me. And not sure, I was just messing around a bit hoping to get it to work. Casey Van Buren, it is actually indented in the file. Otherwise it would've thrown me an error for that :D – maa Nov 15 '17 at 20:36

0 Answers0