Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何通过键入';退出';?_Python_Quit - Fatal编程技术网

Python 如何通过键入';退出';?

Python 如何通过键入';退出';?,python,quit,Python,Quit,你好!每当我输入“退出”或“退出”时,我该如何退出游戏 基本上,我已经创建了一个程序,给你一个混合的、混乱的单词,然后我必须正确地猜测它。当我能够打字时,我想输入quit,以便在必要时退出游戏 提前谢谢!(你不需要知道游戏是如何运行的,我只需要找到一种方法键入quit,然后游戏就会退出) 另外,我应该在哪里输入代码使其退出?如果你只是给我代码,请解释一下 #Word Jumble Game import random import string def jumbled(): words =

你好!每当我输入“退出”或“退出”时,我该如何退出游戏

基本上,我已经创建了一个程序,给你一个混合的、混乱的单词,然后我必须正确地猜测它。当我能够打字时,我想输入quit,以便在必要时退出游戏

提前谢谢!(你不需要知道游戏是如何运行的,我只需要找到一种方法键入quit,然后游戏就会退出)

另外,我应该在哪里输入代码使其退出?如果你只是给我代码,请解释一下

#Word Jumble Game

import random
import string

def jumbled():
words = ['Jumble', 'Star']#, 'Candy', 'Wings', 'Power', 'String', 'Shopping', 'Blonde', 'Steak', 'Speakers', 'Case', 'Stubborn', 'Cat', 'Marker', 'Elevator', 'Taxi', 'Eight', 'Tomato', 'Penguin', 'Custard']
count = 0    
loop = True
loop2 = True
while loop:
word = string.lower(random.choice(words)
jumble = list(word)
random.shuffle(jumble)
scrambled = "".join(jumble) 
while loop2:
    print '\n',scrambled,'\n'
    guess = raw_input('Guess the word: ')
    quit = set(['quit','Quit'])
    choice = 'quit'
    if guess.lower() == word:    
        print '\nCorrect!'
        count+=1
        print "You took",count,"trie(s) in order to get the right answer",jumbled()
    else:
        print '\nTry again!\n'
        count+=1
        if count == 3:
            if words[0]*2:
                print "It looks like you're having trouble!"
                print 'Your hint is: %s'(words) # I'm trying to pull a word from the above list here.



jumbled()

另请参见:

您可以使用另一个
elif
条件

import sys
guess = raw_input('Guess the word: ')
if guess in ['quit','Quit']:
    print "Goodbye!"
    sys.exit()

谢谢兄弟!非常喜欢为什么要注意
guess.trim().lower()='quit'
,因为quit…etc应该都是有效的。甚至我们也可以在['q','quit']中添加:
guess.trim().lower()。
我们还可以添加:stop,exit,bye,再见,f***off,die,^D,我现在需要走了,因为上帝的爱已经退出了,等等。所以在设置测试和你的建议之间,我认为它已经覆盖了。在我键入quit之后,它会一直循环到下一个乱七八糟的单词?它还会打印“再见”吗?
import sys
# ...

if guess.lower() == word:    
    print '\nCorrect!'
    # ...
elif guess.lower() == 'quit':
    sys.exit()    
else:
    print '\nTry again!\n'
    # ...