0

My program is supposed to wait for 10 seconds, and say You lose, then ask the user if he wants to play again. For some reason, my program exits at You lose, without displaying Play again?. This only happens in python.exe. In IDLE, it works fine. I'm confused as to why this is. Can someone help me out? BTW I'm new to python, so please keep the explanations simple. Thank you. Here's the code:

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()
Qartx
  • 27
  • 9
  • You have to make @`chance` `global`! Read: http://stackoverflow.com/questions/15959534/python-visibility-of-global-variables-in-imported-modules – stovfl Apr 17 '17 at 16:30
  • What is the purpose of threading in your code? When you are new to Python why do you start with threading? Why do you use a recursive call? – Claudio Apr 17 '17 at 17:00
  • I'm using threading to run a timer in the background. And I'm learning fast. And I don't know what a recursive call is. And isn't `chance` already `global`? – Qartx Apr 18 '17 at 13:28

0 Answers0