0

I need to create unique numbers for database.

First i'm getting all existing numbers from database:

conn.execute('SELECT numer FROM Brama')
BCheck = conn.getData()

Then i'm creating additional list:

bramy = []

and now with simple loop i'm creating new numbers:

while True:
    numer = random.randint(1,15)
    if numer not in BCheck or bramy:
        bramy.append(numer)
        print(BCheck)
        print(bramy)
        break

And 'if' is skipping conditions: enter image description here

BCheck is list of integers. Any ideas why?

I have tried to force BCheck to be integer, then i checked if BCheck sums(like integer should) and it works.This exact While true loop works with strings in different part of code.

  • Don't include links to pictures of text: just [put that text in your post. As text.](/help/how-to-ask). Also, don't chop up your code, just show the code you're using so that people can read what you did without wondering how much you've omitted. – Mike 'Pomax' Kamermans Dec 12 '22 at 22:54
  • 1
    `or` doesn't work that way. You want `if numer not in BCheck and numer not in bramy:` – Tim Roberts Dec 12 '22 at 22:56
  • 1
    Does this answer your question? [Why does "a == x or y or z" always evaluate to True? How can I compare "a" to all of those?](https://stackoverflow.com/questions/20002503/why-does-a-x-or-y-or-z-always-evaluate-to-true-how-can-i-compare-a-to-al) – mkrieger1 Dec 12 '22 at 22:56
  • Maybe it's off topic, but using a UUID or encrypting a counter is a good alternative. – relent95 Dec 13 '22 at 01:11

0 Answers0