I am trying to make a simple magic eight ball program that asks a question, gives a random response, and then prompts the user if they want to try again. Everything works up until the "ask again" part where all hell breaks loose and this error appears:
TypeError: 'str' object is not callable
I am still very new to Python and quite honestly probably just making a rookie mistake, but there's no shame in asking for help I believe.
Here is the code:
def question():
question = str(input("Ask a yes or no question: "))
replies = ["It is certain",
"It is decidedly so",
"Without a doubt",
"Yes definitely",
"You may rely on it",
"As I see it, yes",
"Most likely",
"Outlook good",
"Yes",
"Signs point to yes",
"Reply hazy try again",
"Ask again later",
"Better not tell you now",
"Cannot predict now",
"Concentrate and ask again",
"Don't count on it",
"My reply is no",
"My sources say no",
"Outlook not so good",
"Very doubtful",
]
rand_num = random.randint(0, 20)
print(replies[rand_num])
def ask_again():
again = input("Would you like to ask another question? (Y/N): ")
if again == "Y" or "y":
question()
elif again == "N" or "n":
print("Thank you and goodbye.")
else:
print("That is not an acceptable answer.")
ask_again()
ask_again()
question()
again == "Y" or "y"does not do what you think it does, see How do I test one variable against multiple values?questionfor two different things: a function and a string. It can't be both, rename one or the other.