The title says it all. I have an infinite loop of randomly generated numbers from one to six that I need to end when 6 occurs twice in a row.
The title says it all. I have an infinite loop of randomly generated numbers from one to six that I need to end when 6 occurs twice in a row.
The following is a working example. With comments in the code so you can better understand each step.
# import required to use randint
import random# holds the last number to be randomly generated
previous_number = None
while True: # infinite loop# generates a random number between 1 and 6num = random.randint(1, 6)# check if the last number was 6 and current number is 6if previous_number == 6 and num == 6:# if the above is true then break out the loopbreak# store the latest number and start the loop againprevious_number = num