2015-04-30 44 views
-3

幾分鐘前,我的程序很好,直到我嘗試添加一個方法來讓用戶被要求再次播放。當我放入循環並縮進所有東西時,當我拿出這個部分時,一些東西變得非常糟糕,因爲它不起作用。現在我不能修復縮進,什麼都不會正常工作。誰能看到明顯的問題?主要函數中的縮進錯誤連接python中的四個問題

def main(): 
    lastRow = 0 
    won = 0 
    draw = False 
    player1turn = True 
    print("Welcome to Connect Four!") 
    rows = input("Please enter a number of rows: ") 
    check = True 
    while check == True: 
      try: 
       if int(rows) <= 4: 
        while int(rows) <= 4: 
         rows = input("Please enter a Valid choice: ") 
        else: 
         check = False 
      except ValueError: 
       rows = input("Please enter a Valid choice: ") 
    columns = input("Please enter a number of columns: ") 
    check2 = True 
    while check2 == True: 
      try: 
       if int(columns) <= 4: 
        while int(columns) <= 4: 
         columns = input("Please enter a Valid choice: ") 
        else: 
         check2 = False 
      except ValueError: 
       columns = input("Please enter a Valid choice: ") 
    myBoard = [] 
    myBoardTemp = [] 
    for i in range(int(columns)): 
      myBoardTemp.append(0) 
      for i in range(int(rows)): 
       myBoard.append([0] * int(columns)) 
    printBoard(myBoard) 
    check3 = True 
    while won == 0 and draw == False: 
      move = input("Please enter a move: ") 
      while check3 == True: 
    try: 
        if int(move) < 0 or int(move) > len(myBoard[0]): 
         while int(move) < 0 or int(move) > len(myBoard[0]): 
           move = input("Please enter a valid choice: ") 
         else: 
           check3 = False 
       except ValueError: 
        move = input("Please enter a valid choice: ") 
    myBoard, player1turn, lastRow = move2(myBoard,int(move) - 1,player1turn) 
    printBoard(myBoard) 
    won = checkWin(myBoard,int(move) - 1, lastRow) 
    draw = isDraw(myBoard, won) 
    if won == 1: 
      print("Player 1 has won!") 
    elif won == -1: 
      print("Player 2 has won!") 
    elif draw == True: 
      print("It is a draw!") 
+6

異常值'嘗試:'是一種ovbious ... –

回答

0

while check3 == True:後,該行不while check3 == True:後正確

+2

這並沒有提供一個問題的答案。要批評或要求作者澄清,請在其帖子下方留言。 –

+0

@ Micheled'Amico:問題在於「代碼修改和重新注入之後的微小錯誤在哪裏?」我的回答:它在那裏和那裏。它究竟如何回答這個問題? – WoJ

0

try縮進不正確縮進,雖然我不知道如果這是一個抄寫錯誤或者是你的原代碼。