gpt4 book ai didi

python - while循环忽略打印?

转载 作者:太空宇宙 更新时间:2023-11-03 18:27:36 25 4
gpt4 key购买 nike

好吧,我正在开发一个基本的骰子游戏,但是当它进入 while 循环时,它不会在里面打印消息,该消息只是一个占位符。

    dicenumber = None
numberchoice = None
ready = None
test = "Lol"

class playerClass():
points = 0


class enemyClass():
point = 0


def rolldice():
dicenumber = dicenumber.randint(1,9)

def start():
print("Hello welcome to the dice game.")
print("The goal of the game is to guess what number the dice will land on.")
print("The option are 1 to 6 and the game is won by getting 3 points.")
print()
print("Are you ready to play?")
print("1 - Yes")
print("2 - No")
ready = int(input())



start()

while ready == 1:
print("hello")

最佳答案

在启动函数中使用全局。另外,当您尝试放置 while ready==1 时,它将处于无限循环中!

dicenumber = None
numberchoice = None
ready = None
test = "Lol"

class playerClass():
points = 0


class enemyClass():
point = 0


def rolldice():
dicenumber = dicenumber.randint(1,9)

def start():
global ready
print("Hello welcome to the dice game.")
print("The goal of the game is to guess what number the dice will land on.")
print("The option are 1 to 6 and the game is won by getting 3 points.")
print()
print("Are you ready to play?")
print("1 - Yes")
print("2 - No")
ready = int(input())



start()

while ready == 1:
print("hello")

关于python - while循环忽略打印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22902345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com