我正在根据流行的美国游戏制作代码生成器,它有 4 个字母的游戏代码。我构建了这个程序来为你生成一个,看看它是否真的存在,但不是四个字母,而是一个被生成四次。
我怎样才能解决这个问题?提前致谢!
import random
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
quantity = int(input('How many codes do you want? '))
def create_code():
for c in range(4):
code = ''
code += random.choice(chars)
return code
for i in range(0, quantity):
print('Your code is', create_code())
Run Code Online (Sandbox Code Playgroud) python ×1