Python 3.x 无法跳出循环
我正试图用类和对象编写一个智囊团游戏,目前我被一些循环所困扰Python 3.x 无法跳出循环,python-3.x,while-loop,Python 3.x,While Loop,我正试图用类和对象编写一个智囊团游戏,目前我被一些循环所困扰 while True: # create a combination # test the combination while game_won == False: print(scoreboard) # player input combination # combination is tested then added to scoreboard tries_left = tries_left+1
while True:
# create a combination
# test the combination
while game_won == False:
print(scoreboard)
# player input combination
# combination is tested then added to scoreboard
tries_left = tries_left+1
if game_won == True:
print(You Won!)
input = Play Again? Y/N
if tries_left == 10:
print(You Lost!)
input = Play Again? Y/N
如何从上一条if语句返回while True->创建组合?(如果左=10:)怎么了
- 您的第一个
中没有任何内容,但如果希望代码位于循环中,则需要在其下缩进代码虽然True
- 有一些打字错误、缺少注释字符和引号
- 当嵌套的while循环
退出时,代码将返回循环父循环while game_won==True
,如果用户愿意,它将重播游戏while True
- 布尔逻辑使用
而不是not
myBool==False
更改为为True时:
,而用户希望播放时:
- 用户输入被删除,忽略空格和小写
- 将赢得的比赛更改为完成的比赛
- 改为使
尝试向左倒计时
- 您的第一个
中没有任何内容,但如果希望代码位于循环中,则需要在其下缩进代码虽然True
- 有一些打字错误、缺少注释字符和引号
- 当嵌套的while循环
退出时,代码将返回循环父循环while game_won==True
,如果用户愿意,它将重播游戏while True
- 布尔逻辑使用
而不是not
myBool==False
更改为为True时:
,而用户希望播放时:
- 用户输入被删除,忽略空格和小写
- 将赢得的比赛更改为完成的比赛
- 改为使
尝试向左倒计时
# Assume user wants to play when the program runs
user_wants_to_play = True
ans = ""
# loop the entire game while the user wishes to play
while user_wants_to_play:
# Create the combination
# Test the combination
# Game isn't done when started
game_done = False
tries_left = 10 # Arbitrary number I chose
while not game_done:
# Play the game
print("Scoreboard")
# Subtract one to tries left
tries_left -= 1
if game_done:
print("You won!")
elif tries_left == 0:
print("You lost!")
game_done = True
# if users answer was 'n'
ans = input("Play again? Y/N \n")
if ans.strip().upper() == 'N':
user_wants_to_play = False