dimanche 14 juin 2020

How do I change the number randomly when I press the button?

I am a student studying Python. I'm making a random number keypad. I want the number of keypad to change randomly again when I press the * button. I added random.shuffle(list,10), but It's not working. What's the problem?

list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
(out0, out1, out2, out3, out4, out5, out6, out7, out8, out9) = random.sample(list,10)

def code(value):
    global pin

    if value == '*':
      if pin == '0000':
          print('PIN OK')
          pin = ''
          e.delete('0', 'end')

      else:
          print('PIN ERROR!', pin)
          pin = ''
          e.delete('0', 'end')
      random.shuffle(list,10)

    else:
        pin += str(value)
        e.insert('end', value)

b9 = tk.Button(root, text = '*', command=lambda:code('*'))



Aucun commentaire:

Enregistrer un commentaire