Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
print = ('Tell me about your pet. ')
about_pet = input()
if 'dog'.lower() in about_pet == True :
print('ah, a dog')
if 'cat'.lower() in about_pet == True :
print ('ooh, a kitty')
print ('Thanks for the story')
when I run this code I get an error:
str object is not callable
What causes this?
print = ('Tell me about your pet. ') overwrites the function print as a string. It's not longer a function after that, so any time you try to call it as a function later, you're going to get errors.
Get rid of the = so you aren't changing what print is.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
i can not get My python code to work it does not replay after i give a answer
Weight = input("Weight: ")
lbsorkg = input("(L)bs or (K)g: ")
if lbsorkg.upper == "K":
FinalPounds = float(Weight) * 2.205
print(f"You are {FinalPounds} pounds")
And I get this
Weight: 12
(L)bs or (K)g: k
Please help me slove this issue
the problem is with the strings' attribute upper, which is not a simple attribute but an instance function.
You must call it, like this:
>>> "k".upper()
'K'
In your case, you should call lbsorkg.upper(), like this:
if lbsorkg.upper() == 'K':
...
I don't understand what's wrong with this.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
x = int(0)
ans1 = int(0)
ans = int(0)
with open('risk_q.txt') as r:
for x in range(12):
mylist = [line.rstrip('\n') for line in r]
ans1 = int(input()) #Error occurs in this line
This error occurred with a different input earlier in the code so I got the input before the function and then passed it through the parameter of the function.
Check back through your code. It appears as though you have used input as a variable name, and therefore overwritten the builtin function.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
phone_letters =[" ", "1", "ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ","*","0","#" ]
key = 0
string = input("Enter a Letter: ",)
while key < 10 :
if string in phone_letters[key]:
print(key)
return key
else:
key = key+1
return "not found"
I am getting error 'return' outside function; I checked indentation and still the error continues.
return may only occur syntactically nested in a function definition
Source: https://docs.python.org/3/reference/simple_stmts.html#the-return-statement
Your return is not nested inside a function. Therefore, the error.
You can use print("not found") if you want to display the text.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
So, I'm trying to make an easter egg in my calculator program, where if you type my friend johns name in, it prints nerd, but I keep getting invalid syntax on the line the if statement starts. here's what the code looks like:
x = input(' ')
if x = John:
print nerd
else:
print x
please keep in mind i'm using python 2.7, not 3. when I googled it, I only got answers that worked in 3.
x = raw_input('enter name ')
if x == 'John':
print 'nerd'
else:
print x
You are doing an assignment, but you need == to check for equality
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I've got a problem with my Python code. For some reason a comparison of two strings is always returning False.
def checkChanged(checkURL, currentMessage):
tempMessage = urllib.urlopen(checkURL)
tempMessage = tempMessage.read()
print (tempMessage + ". " + currentMessage + ".")
if (str(tempMessage) == str(currentMessage)):
print ("equal")
return False
else:
print ("not equal")
return True
(Assume indentation is correct. I had to re-format when inserting here)
The problem I think is the if statement, I have tried many variations where both string weren't enclosed by the str(), I have also tried is instead of == but it is False. I have printed both values on the line before just to check and they are infact equal. Am I missing something?