Confused, help, tell me
The task of the code is to write a 3 letter word that will not be repeated in the list.
import random z = 0 def listSec(s): listSec = '' listSec = listSec + s + '\n' return listSec listToPrint = '' while z < 160: sec = ''.join(random.choice('abcdefghijklmnopqrstuvwxyz') for i in range(3)) for i in range(len(listToPrint)): if sec != listToPrint[i]: print (z) listToPrint += listSec(sec) z += 1 def equal(s, listReit = '', a = 0): for i in range(len(s)): print (i) if s[i] == s[i + 1]: print(s[i]) a = a + 1 listReit = listReit + s[i] print ('reiterative: %s' % (s[i])) return a, listReit print ('Value reiterative: %s, \nlist: %s' % (a, listReit)) #equal(listToPrint) print (listToPrint)
Now the console just hangs without any response.
upd:
import random z = 0 def listSec(s): listSec = '' listSec = listSec + s + '\n' return listSec listToPrint = [] while z < 160: sec = ''.join(random.choice('abcdefghijklmnopqrstuvwxyz') for i in range(3)) a = 0 while a < 1: listToPrint += listSec(sec) a = a + 1 for i in range(len(listToPrint)): k = i + 1 if listSec[i] != listSec[k]: print (z) listToPrint += listSec(sec) z += 1 print (listToPrint) input('press key for exit')
len(listToPrint) = 0
, therefore, you do not enter thefor i in range(len(listToPrint))
loopfor i in range(len(listToPrint))
and the variablez
remains zero. - mkkikrandom.SystemRandom()
oros.urandom()
directly instead ofrandom.Random()
, which is the default. See, also secrets module - jfs