0

After I build and run the code, "Enter word: " is output once and that's it. Stays blank after entering any word. What am I missing? Here's the code:

word = "cool"
guess = " "

while guess != word:
    guess = input("Enter word: ")

print("you win!")
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Sohan J
  • 13
  • 3
  • The indentation is all correct. just got messed up while I posted the question here – Sohan J Aug 27 '18 at 17:40
  • 3
    Which version of python are you using? Also, how are you running the code? – nosklo Aug 27 '18 at 17:42
  • 4
    https://repl.it/repls/UnpleasantImpracticalFont ... you need to be using python 3 (in order to use `input` ,,, otherwise you need `raw_input`) – Joran Beasley Aug 27 '18 at 17:43
  • This works for me in python3. For your input are you doing `cool` or `"cool"`? It works with the double quotes and does not work without them. – d_kennetz Aug 27 '18 at 17:47
  • Its simple: `raw_input()` returns string values, while `input()` return integer values. You have to use `raw_input()`. – Filip Grebowski Aug 27 '18 at 17:49
  • 2
    @FilipGrebowski Since "cool" does not have an integer value, the program would crash. Since it does not crash, the OP is _not_ using Python 2.7. – DYZ Aug 27 '18 at 17:51
  • @DYZ I agree! Thanks! – Filip Grebowski Aug 27 '18 at 17:53
  • I'm using python 3.7...using the sublime editor...raw_input() didn't work either – Sohan J Aug 27 '18 at 18:04
  • For me, your given code works in Python 3.4.5; in Python 2.7, it errors out saying that "name 'cool' is not defined". In neither case do I get your "one-and-done" effect. – Prune Aug 27 '18 at 18:04
  • so this code works in 3.6.1...but not 3.7 , which i'm using – Sohan J Aug 27 '18 at 18:05
  • Please try your code the way we have to: copy it from your posting here, paste it into your editor, and run the result. Do you still see the problem? – Prune Aug 27 '18 at 18:05
  • @Prune yes. Still the same problem...something to do with python 3.7? – Sohan J Aug 27 '18 at 18:14
  • There's nothing wrong with Python 3.7, but you're probably trying to run your code in Sublime Text's console, which is not intended for this, see [this link on ST forum](https://forum.sublimetext.com/t/running-python-on-sublime-console/18621). – Thierry Lathuille Aug 27 '18 at 18:26
  • This runs fine. There is no issue with your code above. You must be compiling it incorrectly. – iceMan33 Aug 27 '18 at 18:28
  • @ThierryLathuille but I installed the sublimeREPL package as well..that should make it work right? – Sohan J Aug 27 '18 at 18:29
  • @MjM8082 yeah code seems to be ok. – Sohan J Aug 27 '18 at 18:30
  • Something strange with sublime editor. The code works fine in PyCharm – Sohan J Aug 27 '18 at 18:51

1 Answers1

0

The code is fine. You just can't input in the Sublime Text terminal from the standard download. That's why it's not doing anything after you type a word and hit enter. Check out this post for a python workout:

Sublime Text Console Input

iceMan33
  • 359
  • 2
  • 16