mercredi 6 novembre 2019

how to terminate python script using while loop and get the result?

i would like to generate random numbers for 5 minutes. after that, i would like to know the most common numbers.

my question is:

can i terminate the script at 1 minute and get the result

my code is as follows:

import random
from collections import Counter
t_end = time.time() + 60*5
numbers = []
while time.time() < t_end:
    number=''.join(map(str, [random.randint(0,9)for value in range(0,4)]))
    numbers.append(number)

print(Counter(numbers))



Aucun commentaire:

Enregistrer un commentaire