Python 3: 'str; object is not callable

Your variable name is a string, not a function. You can see what type your variable is by typing "print(type(name))".

"input()" simply prints the text you give it and saves the next input from the user to that variable. Resulting in that the name variable is a string.

Example:

age = input("What is your age?")

What is your age?

>> 25

age = "25"

print(type(age))

String

Try something like this instead:

#Changed to lowercase to make it easier to compare name and myPets.

myPets = ['zophie', 'pooka', 'fat-tail']

#A while loop keeps repeating this block of code until the condition is no longer true.

while True:

#User makes a guess

name = input("Guess the name of my pets: "

#if condition is met print this, also breaks the loop. Use .lower() on name so you no longer have to be case sensitive.

if name.lower() in myPets:

print(name + " is one of my pets, good job!")

#if condition not met print this, will continue loop.

else:

print(name + " is not one of my pets, keep guessing!")

/r/learnpython Thread