I want to get how many attempts have been made before a random value between 0 and 10 is greater than 8. I have the following code which works correctly:
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)
However, now I want to get the number of attempts before x was greater than 8 for the fourth time. To do this, I placed the for loop just before the while loop which becomes like this:
for i in range(0,4):
while(x < 8):
attempt = attempt + 1
x = np.random.uniform(low=0, high=10, size=1)
However, this is not working as I intended it to be. Can someone help me solve this problem?
xso oncex > 8it stays that way for every interation of your for loop. Putx=0between yourforand yourwhile.