import random
rock = '''
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
'''
paper = '''
_______
---' ____)____
______)
_______)
_______)
---.__________)
'''
scissors = '''
_______
---' ____)____
______)
__________)
(____)
---.__(___)
'''
anci = [rock,paper,scissors]
Opponent_choice = int(input("What do you choose? Type 0 for Rock, 1 for Paper, 2 for Scissors\n"))
print(anci[Opponent_choice])
# ------------------------------------
Comp_choice = random.randint(0,2)
Comp_choice_alt = anci[Comp_choice]
print(f"Computer chose: {Comp_choice} \n {Comp_choice_alt}")
if Opponent_choice==0&Comp_choice == 0:
print("It's a draw")
elif Opponent_choice == 0 & Comp_choice == 1:
print("You lose")
elif Opponent_choice == 0&Comp_choice == 2:
print("You win")
elif Opponent_choice == 1&Comp_choice == 0:
print("You win")
elif Opponent_choice==1&Comp_choice == 1:
print("It's a draw")
elif Opponent_choice == 1&Comp_choice == 2:
print("You lose")
elif Opponent_choice == 2&Comp_choice == 0:
print("You lose")
elif Opponent_choice == 2&Comp_choice == 1:
print("You win")
elif Opponent_choice==2&Comp_choice == 2:
print("It's a draw")
它不显示“你赢了”或“你输了”,有时不像它应该显示“这是一个平局”,它应该打印“你赢了”
我觉得我的if-else语句有问题
3条答案
按热度按时间z31licg01#
将所有单个&更改为'and',请参阅代码。https://www.geeksforgeeks.org/difference-between-and-and-in-python/
vm0i2vca2#
应该使用
and
而不是&
。https://www.geeksforgeeks.org/difference-between-and-and-in-python/
00jrzges3#
除了使用
and
之外,还可以简化条件逻辑。