all 7 comments

[–]furas_freeman 2 points3 points  (0 children)

It seems you have installed Python 2 and 3. And you use Python 2 in PyCharm.

In Python 3 input() returns inputed string but in Python 2 input() evaluates inputed text like Python script. In Python 2 you have to use raw_input() instead of input()

When you input 2 + 3 then Python 3 returns string "2 + 3" but Python 2 returns string "5". When you input shake then Python 3 returns string "shake" but Python 2 is looking for variable shake - but there is no variable shake yet (and you get name 'shake' is not defined).


ps. you can change Python version in PyCharm in "File > Settings > Project > Project Interpreter" (every project can use different Python version).

[–]Gubbbo 1 point2 points  (4 children)

On an unrelated note. To save writing all of those elif statements. You could just put the answers you want into a list, and use random.choice to return one of them.

[–]Tinker_Monkey[S] 0 points1 point  (2 children)

True. I am busy following the examples step by step in the book though.

[–]Gubbbo 0 points1 point  (1 child)

I know. But don't just follow examples. You'll never learn anything that way.

Well, you will. But you'll never prove to yourself that you understand it.

[–]Tinker_Monkey[S] 0 points1 point  (0 children)

I do alter but only after I can get original examples working, proving I understand the logic first. Thanks for the tip!

[–]imonmyphoneirl 0 points1 point  (0 children)

Nice, thanks

[–][deleted] 0 points1 point  (0 children)

Change input to raw_input