mardi 21 avril 2020

can i define k elem in random.sample function as an variable?

I am begginer in Python. And what I am trying to do is make a random text from the list generator, in which you can choose how many things from the list you want to print out. When im trying to make k=var in which var=Entry(...). It gives me this error: TypeError: '<=' not supported between instances of 'int' and 'NoneType'. If you can give me tips to improve my skills and knowledge Id be really happy.

k determines how many items from the list I wanna print out:

def nahodny_generator():
    list = ["more", "more1", "more3"]
    sampling = random.sample(list, k=2)
    oklbl = Label(root, text=sampling)
    oklbl.grid(row=6, column=0)



Aucun commentaire:

Enregistrer un commentaire