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")