-1

i want only int vars in my code. What am i doing wrong?

list = []
x = int 
while True:
    x = int(input("say a number, friend "))
    if x == str:
        print("this isnt a number, fool")
    elif str(x.lower)() == "end":
        break
    list.append(x)
print(list)
  • 1
    Welcome to Stack Overflow. In your own words, what do you expect `str(x.lower)()` to do? Why? Hint: look closely at where the parentheses are. – Karl Knechtel May 21 '22 at 20:19
  • `x = int` what are you trying to do here? – President James K. Polk May 21 '22 at 20:19
  • Please note that the word "is" in English means **many** things, and `==` means **exactly one** of those things. – Karl Knechtel May 21 '22 at 20:20
  • @President Clearly, OP is trying to declare a typed variable. – BoarGules May 21 '22 at 20:50
  • @KarlKnechtel I used x.lower in case someone puts the word end in with uppercase letters, like End or END.I whant to end the loop when the user type end – Kamikaze May 21 '22 at 23:08
  • `x == str` makes no sense. `str` is a type, and is not equal to any individual string. You were probably thinking `isinstance(x, str)`, but in fact `x` will never be a string in any case. It will either be an integer, or your program will throw an exception. – Zorgoth May 22 '22 at 04:54
  • "I used x.lower in case someone puts the word end in with uppercase letters" That doesn't answer my question. Look closely at the line of code. Especially look at how the parentheses are arranged. Do you expect that `x.lower` will be *called*? Why? – Karl Knechtel May 22 '22 at 18:03
  • (Answer: the code means "try to convert the `x.lower` method - not a result from calling it, but the method itself - into a string, and then try to call the string as if it were a function". Hopefully I don't need to explain why this would not work.) – Karl Knechtel May 22 '22 at 18:04
  • @BoarGules good point. I added a duplicate link for that topic. – Karl Knechtel May 22 '22 at 18:07

0 Answers0