Python 不确定为什么我的程序中会出现这些错误

Python 不确定为什么我的程序中会出现这些错误,python,Python,有人知道我为什么在def game()上得到预期的缩进块吗? 另外,我在-play再次缩进“y”时出错。如果你们能给我一些提示,告诉我为什么会发生这些事情,如果你们看到其他任何事情,请告诉我,我们将一如既往地非常感激 import random def main(): player1Score = 0 compScore = 0 Intro() displayMenu() def Intro(): print("Welcome to the Le

有人知道我为什么在def game()上得到预期的缩进块吗? 另外,我在-play再次缩进“y”时出错。如果你们能给我一些提示,告诉我为什么会发生这些事情,如果你们看到其他任何事情,请告诉我,我们将一如既往地非常感激

import random 
def main():
    player1Score = 0
    compScore = 0 

    Intro()
    displayMenu()


def Intro():
    print("Welcome to the League of Rock, Paper, Scissors!")
    print("Where contestants battle it out to see who is the best")


    print("Main Menu")
    print("1 See the rules")
    print("2 play against the computer")
    print("3 play a two player game")
    print("4 Quit")
    decision = int(input("\nEnter choice:"))

    #Input validation
    while decision <= 0 or decision > 4:
        print("'ERROR: You must choose 1,2,3 or 4")
        decision = int(input("Enter your choice:"))

    if decision == 1:
        print("The rules here are simple")
        print("Paper Covers Rock")
        print("Rock smashed Scissors")
        print("Scissors Cut Paper")

    if decision == 4:
        print("Goodbye..Thank you for playing")
    if decision == 2:
        return game()

    if decision == 3:
        return player()

def game():
    player_choice = raw_input('Do you choose rock [r], paper [p], or scissors [s]? ')

    computer_choice = randint(0,2)
    #Rock = 0 Paper = 1 Scissors = 2

    #Player chooses paper, computer chooses rock
    if player_choice == "p" and computer_choice == 0:
        print("Computer chose rock")
        player_won()

    #Player chooses rock, computer chooses scissors
    elif player_choice == 'r' and computer_choice == 2:
        print("Computer chose scissors")
        player_won()

    #Player chooses scissors, computer chooses paper
    elif player_choice == 's' and computer_choice == 1:
        print("Computer chose paper")
        player_won()

    #Computer chooses paper, player chooses rock
    elif player_choice == 'r' and computer_choice == 1:
        print("Computer chose paper")
        computer_won()

    #Computer chooses rock, player chooses scissors
    elif player_choice == 's' and computer_choice == 0:
        print("Computer chose rock")
        computer_won()

    #Computer chooses scissors, player chooses paper
    elif player_choice == 'p' and computer_choice == 2:
        print("Computer chose scissors")
        computer_won()

    #Ties
    elif player_choice == 'r' and computer_choice == 0:
        print("It's a tie!")
        game()

    elif player_choice == 's' and computer_choice == 2:
        print("It's a tie!")
        game()

    elif player_choice == 'p' and computer_choice == 1:
        print("It's a tie!")
        game()

    #Wrong input
    else:
        print("Please try again.")
        game()

def player_won():
    global player_count
    print("You win!")
    player_count += 1
    print("You have ' + str(player_count) + ' point(s).")
    if player_count < 3:
        game()

def computer_won():
    global comp_count
    print("Computer wins!")
    comp_count += 1
    print("Computer has ' + str(comp_count) + ' point(s).")
    if comp_count < 3:
        game()

print("Welcome to Rock, Paper, Scissors! First to 3 points wins it all.")
game()

def player():
   ready = input("Requires two players; Are you ready to play? (y/n) ")
while ready != 'y' and ready != 'n':
    ready = input("Oops, I didn't quite get that.")

def player_1():
     x = input("Player 1 - Pick your mode of attack! ")
     while x != 'Rock'and x !='rock' and x != 'Paper'and x != 'paper'and x != 'scissors'and x !='Scissors':
         x = input("Oops, that won't do you any good... ")
     return x

def player_2():
    x = input("Player 2 - Pick your mode of attack! ")
    while x != "Rock" and x != "rock" and x != "Paper" and x != "paper" and x != 'scissors'and x != 'Scissors':
        x = input("Oops, that won't do you any good... ")
    return x 
def play_again():
    play_again = input("Would you guys like to play again? (y/n) ")
    while play_again != "y" and play_again != "n":
        play_again = input("I'm sorry, what was that? (y/n) ")
            if play_again == "y":
                    return check()
        elif play_again == "n":
            print "Thanks for playing!"

def check():
    Score1 = 2
    Score2 = 2
    while Score1 > 0 and Score2 > 0:
        P1 = player_1()
        P2 = player_2()
        if P1.lower() == P2.lower():
            print("it's a tie!")
        elif P1.lower() == "rock" and P2.lower() == "scissors":
            print("Player 1 Wins!")
            Score1 -= 1
        elif P1.lower() == "paper" and P2.lower() == "rock":
            print("Player 1 Wins!")
            Score1 -= 1
        elif P1.lower() == "scissors" and P2.lower() == "paper":
            print("Player 1 Wins!")
            Score1 -= 1
        else:
            print("Player 2 Wins!")
            Score2 -= 1

        if Score1 == 0:
            print("Congratulations Player 1 for winning best out of three!")
        if Score2 == 0:
            print("Congratulations Player 2 for winning best out of three!")
    play_again()        
check()       


main()
随机导入
def main():
player1Score=0
compScore=0
简介()
显示菜单()
def Intro():
印刷(“欢迎加入石头、布、剪刀联盟!”)
打印(“参赛者在哪里决一胜负,看谁是最好的”)
打印(“主菜单”)
打印(“1见规则”)
打印(“2对电脑播放”)
打印(“3玩两人游戏”)
打印(“4退出”)
decision=int(输入(“\n输入选项:”)
#输入验证
第4号决定:
打印(“错误:必须选择1、2、3或4”)
decision=int(输入(“输入您的选择:”)
如果决策==1:
打印(“这里的规则很简单”)
印刷品(“纸张覆盖岩石”)
印刷品(“碎石头剪刀”)
印刷品(“剪纸”)
如果决策==4:
打印(“再见……感谢您的参与”)
如果决策==2:
返回游戏()
如果决策==3:
返回玩家()
def game():
player_choice=raw_input('您选择石头[r]、纸[p]还是剪刀[s]?)
计算机选择=randint(0,2)
#石头=0布=1剪刀=2
#玩家选择纸张,电脑选择石头
如果玩家选择=p,计算机选择=0:
打印(“计算机选择的摇滚乐”)
玩家_-won()
#玩家选择石头,电脑选择剪刀
elif播放器选项=='r'和计算机选项==2:
打印(“计算机选择的剪刀”)
玩家_-won()
#玩家选择剪刀,电脑选择纸
elif播放器选项==s'和计算机选项==1:
打印(“计算机选择的纸张”)
玩家_-won()
#电脑选择纸张,玩家选择石头
elif播放器选项=='r'和计算机选项==1:
打印(“计算机选择的纸张”)
电脑(元)
#电脑选择石头,玩家选择剪刀
elif播放器选项==s'和计算机选项==0:
打印(“计算机选择的摇滚乐”)
电脑(元)
#电脑选择剪刀,玩家选择纸
elif播放器选项=='p'和计算机选项==2:
打印(“计算机选择的剪刀”)
电脑(元)
#领带
elif播放器选项=='r'和计算机选项==0:
打印(“这是一条领带!”)
游戏()
elif播放器选项==s'和计算机选项==2:
打印(“这是一条领带!”)
游戏()
elif播放器选项=='p'和计算机选项==1:
打印(“这是一条领带!”)
游戏()
#输入错误
其他:
打印(“请重试”)
游戏()
def player_won():
全球玩家数量
打印(“你赢了!”)
玩家计数+=1
打印(“您有'+str(玩家计数)+'点)。”
如果玩家计数小于3:
游戏()
def computer_won():
全局补偿计数
打印(“计算机获胜!”)
复合计数+=1
打印(“计算机有'+str(复合计数)+'点”)
如果comp_计数小于3:
游戏()
打印(“欢迎使用石头、布、剪刀!第一到三分赢得一切。”)
游戏()
def player():
就绪=输入(“需要两名玩家;您准备好玩了吗?(y/n)”)
准备好了!='准备好了n':
ready=input(“哎呀,我不太明白。”)
def播放器_1():
x=输入(“玩家1-选择你的攻击模式!”)
而x!='摇滚乐和x!='摇滚乐和x!='纸和x!='纸和x!='剪刀和x!='剪刀':
x=输入(“哎呀,这对你没有任何好处……”)
返回x
def播放器_2():
x=输入(“玩家2-选择你的攻击模式!”)
而x!=“摇滚乐”和x!=“摇滚乐”和x!=“纸”和x!=“纸”和x!='剪刀和x!='剪刀':
x=输入(“哎呀,这对你没有任何好处……”)
返回x
再次播放()
再次播放=输入(“你们想再次播放吗?(y/n)”)
再玩一次!=“y”再玩一次“n”:
再次播放=输入(“对不起,那是什么?(y/n)”)
如果再次播放_==“y”:
返回检查()
elif play_再次==“n”:
打印“谢谢玩!”
def check():
分数1=2
分数2=2
当分数1>0和分数2>0时:
P1=玩家_1()
P2=玩家_2()
如果P1.lower()==P2.lower():
打印(“这是一条领带!”)
elif P1.lower()=“岩石”和P2.lower()=“剪刀”:
打印(“玩家1获胜!”)
分数1-=1
elif P1.lower()=“纸张”和P2.lower()=“岩石”:
打印(“玩家1获胜!”)
分数1-=1
elif P1.lower()=“剪刀”和P2.lower()=“纸”:
打印(“玩家1获胜!”)
分数1-=1
其他:
打印(“玩家2获胜!”)
得分2-=1
如果分数1==0:
打印(“祝贺玩家1赢得三选一的最佳结果!”)
如果分数2==0:
打印(“祝贺玩家2赢得三选一的最佳成绩!”)
再玩一次
检查()
main()

非常确定您不应该使用
elif
if
,因为上面没有
if
语句


另外,我认为您不需要在函数中返回H1。

为什么在
elif H1==1:
之前有一个return语句?您的第一行也有不好的缩进。这是原始代码吗?谢谢你,因为你修复了我的第一个问题,哈哈,是的,这是原始代码,但当我把它转移到这里时,我搞砸了。程序现在运行了,再次感谢你,现在我只需要找出两人模式:驻留,如果它工作正常,那么你可以保留它,但是除非你使用函数来确定其他东西的值,否则你并不真正需要它。