这是一个非常简单的掷骰子程序,它不断掷两个骰子,直到得到双 6。所以我的 while 语句结构如下:
while DieOne != 6 and DieTwo != 6:
Run Code Online (Sandbox Code Playgroud)
出于某种原因,该计划在DieOne获得 6 分后立即结束。DieTwo根本不考虑。
但是如果我将 while 语句中的theand改为 an or,程序就可以完美运行。这对我来说没有意义。
import random
print('How many times before double 6s?')
num=0
DieOne = 0
DieTwo = 0
while DieOne != 6 or DieTwo != 6:
num = num + 1
DieOne = random.randint(1,6)
DieTwo = random.randint(1,6)
print(DieOne)
print(DieTwo)
print()
if (DieOne == 6) and (DieTwo == 6):
num = str(num)
print('You got double 6s in …Run Code Online (Sandbox Code Playgroud)