首页 > 解决方案 > 为什么我的石头剪刀布游戏不启动while循环?

问题描述

所以这是我到目前为止的代码,试图制作一个最好的三分之二的石头剪刀布游戏。

from random import randint
print("Rock...")
print("Paper...")
print("Scissors...")

player_wins = 0
computer_wins = 0

while player_wins and computer wins < 3:  
    player1 = input("Player 1, make your move: ").lower()
    computer_choices = ["rock", "paper", "scissors"]
    computer_choice = randint(0, 2)
    computer = str[computer_choices[computer_choice]]
    print(computer)
...(then all the choice logic goes here, I add 1 to the variables of the one who wins)

if player_wins == 3:
    print("Player wins the game!")
if computer_wins == 3:
    print("Computer wins the game!")

代码从不进入while循环,怎么回事?我真的不知道这里发生了什么。

编辑:我做了while (player_wins and computer_wins) < 3:,现在它进入循环但不退出。

标签: pythonwhile-loop

解决方案


你可能想要:

while (player_wins < 3) and (computer wins < 3):  

看起来您试图说 player_wins 和 computer_wins 是否都 < 3,但您的语法不太正确。


推荐阅读