Determining Continuous Values

Asked 2 years ago, Updated 2 years ago, 19 views

If I keep printing 1 and 2 randomly on Python and 1 or 2 come out 3 times in a row, I want to end the program, but what should I do with the code that has a specific value in a row?

python

2022-09-22 19:27

1 Answers

import random
count = 0
arr = [0]*3

while True:
    a = random.randint(1, 2)

    arr[count] = a

    b = arr[0] + arr[1] + arr[2]

    if count == 2:
        if b == 6 or b == 3:
            print(arr)
            b = 0
            arr = [0]*3
            count =0
            break

        else:
            b = 0
            arr = [0] * 3
            count = 0
            continue

    else:
        count += 1
        continue

If you do this, you can print it out as you want.


2022-09-22 19:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.