-4

I'm trying to make my program print a serial with a base and two randoms

import random
import string

charList = "A", "B", "C", "D", "C", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5"
"6", "7", "8", "9"
y27Base = ["U0330V", "U0330W", "U0330X", "U0330Y"]

whatSerial = input("What serial?").upper()

def y27(y27Base, charList):
    return y27Base + "".join([random.choice(charList) for x in range(2)]) + " -> Y27"
if whatSerial == "Y27F":
    for i in y27Base:
        for i2 in charList:
            print(y27(i, i2))

what I want is for the program to print y27Base with 2 randoms so for e.x

U0330V9D U0330XZ7

and I'd want it to print as many as possible

Thanks alot in advance

Prune
  • 76,765
  • 14
  • 60
  • 81
verbids
  • 55
  • 6

1 Answers1

1

Your critical problem is that you pass single characters to the function:

    for i2 in charList:
        print(y27(i, i2))

Thus, your function has only one character from which to choose, and you get the double letters that plague your output.

To fix this, simply pass in the character list from your main program:

for i in y27Base:
    print(y27(i, charList))

Output:

U0330VFG -> Y27
U0330WDC -> Y27
U0330XEM -> Y27
U0330YCI -> Y27

There is no limit to "as many times as possible": you can loop on this inner statement as much as you like.

Prune
  • 76,765
  • 14
  • 60
  • 81