def game()でインデントされたブロックが得られる理由を知っている人は誰ですか? また、インデント再生時にエラー「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()
なぜあなたは 'elif H1 == 1:'の直前にreturn文を持っていますか? –
最初の行にもインデントがありません。元のコードですか? –
私は最初の問題を解決したのでうれしく思います。元のコードですが、ここに転送したときにはうんざりしてしまいました。プログラムは今すぐ実行されますので、私はちょうど2つのプレーヤーモードを把握する必要があります:D – Pogammagamma