You have a few mistakes in your code. The first, is that I'm not entirely sure what the
roll = [(dice1, dice2) for i in range(count)]
line is doing for you.
You can make a few simple changes though.
First - your record.append(...)
line is outside of your loop. That is why you only see the previous run. It's only recording one run.
Second, your while
statement can be a simple while True:
with a break
in it when you meet your matching condition. You don't need the stop
variable.
from random import randint
count = 0
record = []
while True:
dice1 = randint(1,6)
dice2 = randint(1,6)
record.append([dice1,dice2])
if dice1 != dice2:
count += 1
else:
break
if count == 0:
print("You roll same number for both dice at first try!")
else:
print(f"You roll same number for both dice after {count+1} attempts.")
print("The past record of dice rolling as below: ")
print(record)
With output similar to this:
You roll same number for both dice after 8 attempts.
The past record of dice rolling as below:
[[1, 6], [2, 1], [1, 6], [5, 6], [5, 3], [6, 3], [6, 5], [4, 4]]
Notice that I've brought the .append(...)
into your while loop. I've also made the changes around the stop
variable as I described.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…