python - 为什么我的石头剪刀布游戏不启动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:
,现在它进入循环但不退出。
解决方案
你可能想要:
while (player_wins < 3) and (computer wins < 3):
看起来您试图说 player_wins 和 computer_wins 是否都 < 3,但您的语法不太正确。
推荐阅读
- go - 给定一个端口,在 Golang 中返回相应的服务(例如 http、ssh、...)
- css - 粘性表格标题滚动问题
- javascript - 为什么这个 axios.get 请求不起作用>?
- javascript - 单行子对象检查
- android - Kotlin Coroutines - 跳转功能
- c++ - g++10 中的 C++20:未定义生成器
- android - java.io.IOException:Android Firebase 中的 AUTHENTICATION_FAILED(和 SERVICE_NOT_AVAILABLE)
- javascript - JavaScript 类切换
- java - 如何控制在我的窗口或 JFrame 面板中出现的位置
- reactjs - ReactJS KonvasJS 如何创建不能重叠的 2 层