0

I am completely new to programming. I have the book Learn To Program With Minecraft: Transform Your World With The Power Of Python. There is no real customer support for the book.

I'm learning about Logical Operator Order. The book presents the following code as an example:

wolves = input("Enter the number of wolves: ")
enoughWolves = wolves > 10 and wolves < 20
print("Enough wolves: " + str(enoughWolves))

I wrote the code exactly as the book said, but I got the following error:

Traceback (most recent call last):
  File "/Users/myName/Documents/wolves.py", line 3, in <module>
    enoughWolves = wolves < 20
TypeError: '<' not supported between instances of 'str' and 'int'

I don't understand what this error message means, and I don't understand why the book's code doesn't work. Can anyone help me?

  • Either the book's code is wrong, or you copied it wrong, or it was written for Python 2, where `input` worked differently. – khelwood Aug 16 '20 at 13:58
  • From 2.7 documentation, calling `input()` is equivalent to calling `eval(raw_input(prompt))`, which is different from version 3 onwards, where `input()` always returns a `str`object. So you can see that previously objects like `int` could be created automatically by `eval` of an `str`, while now that does not happen. – progmatico Aug 16 '20 at 14:56
  • Welcome to Stack Overflow! Take some time reading the [Help Center](https://stackoverflow.com/help) if you have not read it yet. – progmatico Aug 16 '20 at 14:59

0 Answers0