簡體   English   中英

我正在嘗試在 python 中制作一個石頭剪刀布游戲,但我得到一個 unindent 與任何外部縮進桿錯誤不匹配

[英]I'm trying to make a rock paper scissors game in python, but am getting an unindent does not match any outer indent lever error

這是代碼。 錯誤出現在input("Do you want to continue?")行。

import random

def play():
    gameOver = False
    while not gameOver: 
        imput = input("rock, paper, or scissors?")
        j = 0
        if (imput == "rock"):
            j = 1
        elif(imput == "paper"):
            j = 2
        else:
            j = 3

        robot = random.randint(1,3) 

        if j == robot:
            print("you got the same thing")
        elif j == 1:
            if robot == 2:
                print("Rock vs Paper, you lose")
            else:
                print("Rock vs Scissors, you win!")
        elif j == 2:
            if robot == 1:
                print("paper vs rock, you win!")
            else:
                print("paper vs scissors, you lose")

        else:
            if robot == 1:
                print("Scissors vs Rock, you lose")
            else:
                print("Scissors vs paper, you win!")
        
        decision = input("Do you want to continue?")
        if decision == "yes":
            gameOver == True

play()

運行您發布的此代碼時,我沒有收到解析錯誤。 我的猜測是制表符與空格。 將編輯器的設置更改為在按下制表鍵時始終使用 4 個空格,並查找並替換任何現有的制表符以替換為 4 個空格。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM