dimanche 9 avril 2017

Looking for an occurrence in a random number

I wrote the following:

import random

count = 0
while count < 10000:
    num = random.uniform(0,999)
    print num
    if num == 777:
        print "Gotcha!"
        break
    count += 1
else:
    print "Done."

As you can see, if the generated number is 777 it outputs Gotcha. The numbers I generate are like 3.837810489 and 5.92304723. What I need is it to keep a number and any part of it has a sequence of 777 like 4.397779210 but I did not find on Python documentation anything to help me on that task.

Thank you for the help!




Aucun commentaire:

Enregistrer un commentaire