name = raw_input("Welcome soldier. What is your name? ")
print('Ok,', name, ' we need your help.')
print("Do you want to help us? (Yes/No) ")
ans = raw_input().lower()
while True:
ans = raw_input().lower()("This is one of those times when only Yes/No will do!" "\n" "So what will it be? Yes? No?")
ans = raw_input().lower()
if ans() == 'yes' or 'no':
break
if ans == "yes":
print ("Good!")
elif ans == "no":
print("I guess I was wrong about you..." '\n' "Game over.")
When I answer this happens;
First a blank line, then if I press the enter key again;
File "test.py", line 11, in <module>
ans = raw_input().lower()("This is one of these times when only Yes/No will
do!" "\n" "So what will it be? Yes? No?")
TypeError: 'str' object is not callable
What seams to be the problem?
P.S I searched the site but it seams that all the people with the same problem had far more advanced scripts and I did not understand anything.
The first error is in the line
The result of
lower()is a string, and parentheses after that mean that the object on the left (the string) gets called. Therefore, you get your error. You wantAlso,
does not what you expect. Again,
ansis a string, and parentheses mean that the object on the left (the string) gets called. Therefore, you get your error.Also,
oris a logical operator. Even after removing the parentheses afterans, the code gets evaluated as:Since a non-empty string (
'no') evaluates to the boolean value True, this expression is always True. You simply wantAdditionally, you want to unindent the last lines. All in all, try: