0

I tried quit(0) and sys.exit too

import random 

word = random.choice(open(r"C:\Users\Sigma.jota3\Documents\new.txt").read().split()).strip()
word = list(word)
print ' '.join(word)

word_2 = []

for i in range(len(word)):
    word_2.append("_")

print ' '.join(word_2)


word_3 = [] 


count = 0 


numbers_to_count = len(word)


while True:    

    word_input = raw_input("")     

    word = ''.join(word) 

    for el in range(len(word)):
        if not word[el] != word_input:
            word_3.append(word[el])
            numbers_to_count = numbers_to_count - 1 
            print "your answer is right!, now you have %s letters to resolve!" % numbers_to_count
        if numbers_to_count == 0:
            print "Congratulations, you win!"
            exit(0) 
        if numbers_to_count < 0:
            exit(0) 

    for le in range(len(word)):
        word_word_input = word.find(word_input)  
        if word_word_input < 0: 
            count = count + 1
            print "Try again, you have failed in %s times!" % count
        if count > 7:
            print "Tip: The word have %s letters." % len(word)  
        if count > 12:
            print "You lose!, you made more than %s tries." % count
            exit(0)
4
  • 3
    What is the error ? Please edit the question and mention the stack-trace Commented Jan 17, 2017 at 19:18
  • 1
    exit is not a global function; it's defined in the sys module. So, you'd need import sys at the top of the script, and sys.exit(0) to actually exit. Or alternatively, from sys import exit at the top, and leave the exit(0)s alone. Commented Jan 17, 2017 at 19:20
  • oh, thanks jason, i will see it now Commented Jan 17, 2017 at 19:27
  • im still having troubles with the code Commented Jan 17, 2017 at 19:32

1 Answer 1

0

You do not have import sys in your code. If you do have the import in your code, then sys.exit() how to use it python I also see in your code that you use exit(0). That will only work if you have from sys import exit However since you say that you tried sys.exit(0), then you probably need to have the import statement added.

sys.exit() raises a SystemExit exception. This may be what you are seeing

Traceback (most recent call last):
line xx, in <module>
sys.exit()
SystemExit
Sign up to request clarification or add additional context in comments.

7 Comments

i used the import sys in this code when i used sys.exit(0)
What troubles are you having?
well, in the cmd, the code exit - but in the console of python, not
@GuilhermeRafael I do not understand what you mean
the code really quits and exits of python console when the game is over in the cmd
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.