Python 3x - Error: "Object" is no defined in list

Asked

Viewed 39 times

1

I am learning to program in python and I have this following problem in an exercise. When running the code happens this following error:

vogal = (a,e,i,o,u) 
NameError: name 'a' is not defined.

I have tried to solve by typing some other codes, writing the same code in other ways and even then I continue with the error.

    vogal = [a,e,i,o,u]

    letra = input("Digite uma letra: ")

    if letra in vogal:

    print('esta letra é uma vogal')

else:

print('esta letra não é uma vogal')
  • 1

    If the intention was that a,e,i,o,u were strings, literal values, put them in quotes: vogal = ["a","e","i","o","u"]

  • Oops, it worked out, thank you very much, I hadn’t paid attention to this little detail. I ended up thinking it was a more complicated problem but no. Hugs

1 answer

2


The right thing would be:

vogal = ('a','e','i','o','u') 

The reason is that, in Python (and in general programming languages), when you want to use a string it must be typed in quotes.

Without using quotes the typed word will be understood as a variable, and there is no variable to stated in your code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.