I am making a serial key generator for a school exercise, and I am running into a small problem. When I run the program, and type in I want to make 20 serial keys, the program will make twenty of the same keys. The cause of this is in the for loop making variables every time it passes by. (The v{0} thing)
I can not figure out how to use another method to read all the values in a list, and create variables out of them.
My code:
import random, sys
class Application:
def __init__(self):
global i
i = int(input("How many serial codes do you want to create?\n"))
print("")
self.main(i)
def main(self, i):
seq = "ABCDFGHJIKLMNOPQRSTUVWXYZ1234567890"
store = []
for z in range(0, i):
for x in range(0, 5):
first = random.choice(seq)
second= random.choice(seq)
third = random.choice(seq)
fourth =random.choice(seq)
fifth = random.choice(seq)
serial = first + second + third + fourth + fifth
store.append(serial)
for y, item in enumerate(store):
setattr(sys.modules[__name__], 'v{0}'.format(y), item)
create = v0 + "-" + v1 + "-" + v2 + "-" + v3 + "-" + v4
print(create)
print("\nCreated", i, "serial keys!")
if __name__ == '__main__':
app = Application()