程序退出python.exe但不在IDLE中

时间:2017-04-17 14:42:02

标签: python multithreading python-3.x

我的程序应该等待10秒,然后说You lose,然后询问用户是否要再玩一次。出于某种原因,我的程序会在You lose退出,而不会显示Play again?。这只发生在python.exe中。在IDLE,它工作正常。我很困惑为什么会这样。有人可以帮我吗? 顺便说一下我是python的新手,所以请保持简单的解释。谢谢。 这是代码:

import Dictionaries
import threading
import random
import time
import sys
global permit
permit='yes'
point='NUB'
def timer():
    if permit in ['yes','Yes']:
        if point=='NUB':
            global chance
            chance='no'
            print('You lose')
            time.sleep(1)
def code():   
    global permit
    permit='yes'
    global point
    while permit in ['yes','Yes']:
        Dictionaries.insane()
        word=[]
        c=random.choice(Dictionaries.allwords)
        answer=c
        global chance
        chance='allow'
        while chance=='allow':
            for x in c:
                word.append(x)
                p=0
                words=''
            while p!=len(c):
                x=random.choice(word)
                word.remove(x)
                words=words+x
                p+=1
            print(words)
            guess=input()
            if guess==answer:
                point='NOICE'
                print(point)
            else:
                point="NUB"
                print(point)
        permit=input('Play Again?')
    print('Are you sure you want to exit?')
    exiting=input()
    if exiting in ['sure','Sure']:
        sys.exit()
    else:
        code()   
t1=threading.Timer(10.0,timer)
t2=threading.Thread(target=code)
t2.daemon=True
t1.start()
t2.start()

0 个答案:

没有答案