mardi 5 janvier 2021

Can i get a random number of choices in python? [duplicate]

This is my program code:

import random
x = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
y = ("1","2","3","4","5","6","7","8","9","0")
z = ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z")
a = (random.choice(x) + random.choice(x) + random.choice(x) + random.choice(x))
b = (random.choice(y) + random.choice(y) + random.choice(y) + random.choice(y))
c = (random.choice(x) + random.choice(x) + random.choice(x) + random.choice(x))

print("Join Code: " + a + "-" + b + "-" + c)

#Test 1

ba = random.choice(y)

ab = random.choices(x, k=ba)

print(ab)

#test 2

ba = random.choice(y)

ab = random.choices(x, k=random.choice(y))

It works but I wanted it to be like the first Join Code... ykvcied or [ykvcied] and not ['y', 'k', 'v', 'c', 'i', 'e', 'd']




Aucun commentaire:

Enregistrer un commentaire