Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11691

python while loop if all conditions are equal then do another random choice from list

$
0
0

This is my python code:

import secretsfrom time import sleepids = [{'id': number} for number in range(1, 20+1)]rand1 = secrets.choice(ids)rand2 = secrets.choice(ids)rand3 = secrets.choice(ids)n = 0while rand1['id'] == rand2['id'] == rand3['id']:        n += 1        print('Before')        print(rand1['id'], rand2['id'], rand3['id'])        sleep(1)        rand1 = secrets.choice(ids)        rand2 = secrets.choice(ids)        rand3 = secrets.choice(ids)        print('After')        print(rand1['id'], rand2['id'], rand3['id'])

I'm going to reach this:

do the while loop and choose a random id until none of the rand1['id'], rand2['id'] and rand3['id'] are equal

Viewing all articles
Browse latest Browse all 11691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>