while answer == 'Y':
roll = get_a_roll()
display_die(roll)
if roll == first_roll:
print("You lost!")
amount_won = roll
current_amount = amount_earned_this_roll + amount_won
amount_earned_this_rol = current_amoun
print("You won $",amount_won)
print( "You have $",current_amount)
print("")
answer = input("Do you want to go again? (y/n) ").upper()
if answer == 'N':
print("You left with $",current_amount)
else:
print("You left with $",current_amount)
这里使用这种循环的目的是在一场比赛中,滚动骰子,你得到回报的钱根据您的卷数,除非你滚轧符合第一滚。现在,如果发生这种情况,我需要循环停止,并且我知道使用break语句很容易实现这一点,但是,我已经被告知不允许break语句。如果roll == first_roll,我怎么能得到循环终止?打破了蟒蛇循环不使用破
你可以将你的代码封装在一个函数中,然后使用'return'语句退出。 – jramirez
或者创建另一个布尔变量,并在while语句中使用'and'检查它的值 – jacktheripper