How do I loop this python script? For example I want 100 of the GGIXX-XXXXXXX
import random
def random_gen():
return f".type('GGI{random.randint(1, 50)}-{random.randint(1000000, 9999999)}')"
How do I loop this python script? For example I want 100 of the GGIXX-XXXXXXX
import random
def random_gen():
return f".type('GGI{random.randint(1, 50)}-{random.randint(1000000, 9999999)}')"
Use a loop:
import random
def random_gen():
return f".type('GGI{random.randint(1, 50)}-{random.randint(1000000, 9999999)}')"
for _ in range(100):
print(random_gen())
Out:
.type('GGI45-5220704')
.type('GGI37-3996932')
.type('GGI2-6482051')
.type('GGI36-2371399')
.type('GGI9-6880645')
.type('GGI12-1733716')
...
You can use a for
statement or a while
statement.
A for
loop is used for iterating over a sequence. With the while
loop we can execute a set of statements as long as a condition is true.
For Loop
import random
def random_gen():
return f".type('GGI{random.randint(1, 50)}-{random.randint(1000000, 9999999)}')"
for i in range(100):
print("{:03}: {}".format(i, random_gen()))
While Loop
import random
def random_gen():
return f".type('GGI{random.randint(1, 50)}-{random.randint(1000000, 9999999)}')"
i = 0
while i < 100:
print("{:03}: {}".format(i, random_gen()))
i += 1
The output will be the same:
000: .type('GGI50-2461961')
001: .type('GGI14-3540227')
002: .type('GGI42-2802782')
003: .type('GGI50-9538359')
004: .type('GGI13-2128867')
005: .type('GGI22-8774426')
006: .type('GGI24-6997243')
007: .type('GGI38-4704988')
008: .type('GGI38-7738663')
009: .type('GGI8-5558144')
010: .type('GGI13-5474296')
...
090: .type('GGI3-4898938')
091: .type('GGI36-4209837')
092: .type('GGI18-6721739')
093: .type('GGI49-8878156')
094: .type('GGI16-2819595')
095: .type('GGI16-1172404')
096: .type('GGI24-2772872')
097: .type('GGI35-9967247')
098: .type('GGI25-8327445')
099: .type('GGI9-4671711')
Here you can find more info:Python docs