2017-04-19 5 views
-6
RANDOM_COR=random.randrange(5,6) 

def check_xy_data():     

    global COUNT 
    COUNT=0 

    input_xy=input("input(x,y) : ") 

    think_xy=list(map(int,input_xy.split(","))) 

    if(random_array[think_xy[0]][think_xy[1]] == "C"): 
     screen_array[think_xy[0]][think_xy[1]] = "O" 
     COUNT=COUNT+1 
    else: 
     screen_array[think_xy[0]][think_xy[1]] = "X" 



def main(): 

    make_intro() 

    init_screen_array() 
    init_random_array() 

    make_random_num(RANDOM_COR) 


    while(True): 
     check_xy_data() 

     draw_outline_start(TOTAL_COL_NUM//2) 

     draw_out_rowline(TOTAL_COL_NUM//2, "Input : ") 
     draw_out_rowline(TOTAL_COL_NUM//2, "Correct : ") 
     draw_out_rowline(TOTAL_COL_NUM//2, "Error : ") 
     draw_out_rowline(TOTAL_COL_NUM//2, "Total : ") 

     draw_outline_mid(TOTAL_COL_NUM//2) 
     if(COUNT==RANDOM_COR-1): 
      break 

The if at the bottom of my code is supposed to get me out of the while loop、but I'm stuck in an infinite loop。 Help?Why does my while loop not stop?

(assignment、2016)予告編The Assignment |語サインベッド監督:ウォルター・ヒル脚本:ウォルター・ヒル、デニスハミル出演:キム・ソンフン出演ヒョンビン、ユ・ヘジン、キム・ジュヒョク開封2016韓国詳細を見るこれまで...

+4

You reset 'COUNT' at the start of every call to' check_xy_data'。 – user2357112

+2

Try printing the variable that you expect to control breaking ... – kabanus

+1

Typically、ALL_CAPS identifiers in Python indicate constants。 Not really cool to be using them for variables you're changing。 –

答えて

2

Try this change:

RANDOM_COR=random.randrange(5,6) 
COUNT = 0 

def check_xy_data():     

    global COUNT 

With COUNT inside check_xy_data、you set it back to 0 on every call。 It can never reach more than 1 Your check is whether it's in the range 5-6 This is never true、so you can never leave the loop。

Note that trivial debugging skills would have found this:just stick a print statement before you test your loop condition、to see what the values are。 Use that next time ... :-)

+0

Thank you very much。 –