我不断收到此 IndentationError:意外缩进错误

时间:2021-01-18 18:13:01

标签: python-3.x atom-editor indentation

文件“E:\P-L\Atom\RPS.py\RPS.py”,第 34 行 如果 user_choice == "r": 缩进错误:意外缩进

我是代码新手,我正在做一个项目 有人说你通过做项目学得更好 所以我来了

我在 Atom 上得到这个 我已经在 repl.it 上尝试了相同的代码并且它有效

import random

comp_wins = 0
player_wins = 0

def Choose_Option():
    user_choice = input("Choose Rock, Paper or Scissors: ")
    if user_choice in ["Rock", "rock", "r", "R"]:
        user_choice = "r"
    elif user_choice in ["Paper", "paper", "p", "P"]:
        user_choice = "p"
    elif user_choice in ["Scissors", "scissors", "s", "S"]:
        user_choice = "s"
    else:
        print("I don't understand, try again.")
        Choose_Option()
    return user_choice

def Computer_Option():
    comp_choice = random.randint(1, 3)
    if comp_choice == 1:
        comp_choice = "r"
    elif comp_choice == 2:
        comp_choice = "p"
    else:
        comp_choice = "s"
    return comp_choice


while True:
    print("")
    
    user_choice = Choose_Option()
    comp_choice = Computer_Option()

    print("")
    if user_choice == "r":
         
        if comp_choice == "r":
            print("You chose rock. The computer chose rock. You tied.")
        
        elif comp_choice == "p":
            print("You chose rock. The computer chose paper. You lose.")
            comp_wins += 1
            
        elif comp_choice == "s":
            print("You chose rock. The computer chose scissors. You win.")
            player_wins += 1

    elif user_choice == "p":
        if comp_choice == "r":
            print("You chose paper. The computer chose rock. You win.")
            player_wins += 1
        
        elif comp_choice == "p":
            print("You chose paper. The computer chose paper. You tied.")
            
            
        elif comp_choice == "s":
            print("You chose paper. The computer chose scissors. You lose.")
            comp_wins += 1

    elif user_choice == "s":
        if comp_choice == "r":
            print("You chose scissors. The computer chose rock. You lose.")
            comp_wins += 1
        
        elif comp_choice == "p":
            print("You chose scissors. The computer chose paper. You win.")
            player_wins += 1
            
        elif comp_choice == "s":
            print("You chose scissors. The computer chose scissors. You tied.")

    print("")
    print("Player wins: " + str(player_wins))
    print("Computer wins: " + str(comp_wins))
    print("")
    
    user_choice = input("Do you want to play again? (y/n)")
    if user_choice in ["Y", "y", "yes", "Yes"]:
        pass
    elif user_choice in ["N", "n", "no", "No"]:
        break
    else:
        break

很确定问题出在原子上,但我不知道它是什么,希望得到任何帮助。

0 个答案:

没有答案