我想知道在 0 到 10 之间的随机值大于 8 之前已经进行了多少次尝试。我有以下代码可以正常工作:
import numpy as np
x = np.random.uniform(low=0, high=10, size=1)
attempt = 1
while(x < 8):
attempt = attempt + 1
x = np.random.uniform(low=0, high=10, size=1)
但是,现在我想第四次获得 x 大于 8 之前的尝试次数。为此,我将 for 循环放置在 while 循环之前,如下所示:
for i in range(0,4):
while(x < 8):
attempt = attempt + 1
x = np.random.uniform(low=0, high=10, size=1)
但是,这并没有按我的预期工作。有人可以帮我解决这个问题吗?