これまでにゲームをプレイしてプレイしようとすると、first_player(first_choice)が常に勝ちます。それを理解しようとした後、最初のif文をランダムなprint文で置き換え、毎回それを印刷します。私が間違っているのか理解していない:私のプログラムは2つの変数(first_choiceとsecond_choice)を比較しません
while True:
import os
print("Welcome to the rock, paper, sisers Game")
first_player = input("Player 1 enter your name: ")
second_player = input("Player 2 enter your name: ")
print("Use p for paper, r for rock, and s for sisers")
first_choice = str(input("{} Pick: ".format(first_player)))
os.system('cls' if os.name == 'nt' else 'clear')
second_choice = str(input("{} Pick: ".format(second_player)))
os.system('cls' if os.name == 'nt' else 'clear')
if (first_choice == "r" or "R") and (second_choice == "s" or "S"):
print("{} Won!!!!!".format(first_player))
elif (second_choice == "r" or "R") and (first_choice == "s" or "S"):
print("{} Won!!!!!".format(second_player))
elif first_choice == second_choice:
print("It is a draw")
elif (second_choice == "s" or "S") and (first_choice == "p" or "P"):
print("{} Won!!!!!".format(second_player))
elif (second_choice == "p" or "P") and (first_choice == "s" or "S"):
print("{} Won!!!!!".format(first_player))
elif (second_choice == "p" or "P") and (first_choice == "r", "R"):
print("{} Won!!!!!".format(second_player))
elif (second_choice == "r" or "R") and (first_choice == "p" or "P"):
print("{} Won!!!!!".format(first_player))
は、最初のif文の印刷機能に置き換え:
while True:
import os
print("Welcome to the rock, paper, sisers Game")
first_player = input("Player 1 enter your name: ")
second_player = input("Player 2 enter your name: ")
print("Use p for paper, r for rock, and s for sisers")
first_choice = str(input("{} Pick: ".format(first_player)))
os.system('cls' if os.name == 'nt' else 'clear')
second_choice = str(input("{} Pick: ".format(second_player)))
os.system('cls' if os.name == 'nt' else 'clear')
if (first_choice == "r" or "R") and (second_choice == "s" or "S"):
print("useless random text")
elif (second_choice == "r" or "R") and (first_choice == "s" or "S"):
print("{} Won!!!!!".format(second_player))
elif first_choice == second_choice:
print("It is a draw")
elif (second_choice == "s" or "S") and (first_choice == "p" or "P"):
print("{} Won!!!!!".format(second_player))
elif (second_choice == "p" or "P") and (first_choice == "s" or "S"):
print("{} Won!!!!!".format(first_player))
elif (second_choice == "p" or "P") and (first_choice == "r", "R"):
print("{} Won!!!!!".format(second_player))
elif (second_choice == "r" or "R") and (first_choice == "p" or "P"):
print("{} Won!!!!!".format(first_player))
if(first_choice == "r"またはfirst_choice == "R")と(second_choice == "s"またはsecond_choice == "S") 'として条件を書き直してみてください。 – Antimony
私は素早く見ていましたが、間違って比較しています。 '' first_choice == "r"またはfirst_choice == "R" 'を使うと' 'first_choice ==" r "または" R " ' – sphere