-1

my code:

import random

print("AI THAT WILL FIND OUT YOUR 5 letter text")
ttt = input()

fin = False
lenof = 25
s = 0
used = []
lol = False
used =  []

five = ['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']

while fin == False:
    for i in five:
        ran = random.randint(s,lenof)
        r = five[ran]
        ran1 = random.randint(s,lenof)
        r = r + five[ran1]
        ran2 = random.randint(s,lenof)
        r = r + five[ran2]
        ran3 = random.randint(s,lenof)
        r = r + five[ran3]
        ran4 = random.randint(s,lenof)
        r = r + five[ran4]
        e = r

        if r == ttt:
            fin = True
            lol = True
            print(">> " + r)
        elif r != ttt and lol == False and used.index(r) is None:
            print("> " + r)
            used.append(e)

the error:

  File "<string>", line 38, in <module>
ValueError: 'ntzhk' is not in list

So can you please tell me how to check if a value in an array is None or not?

do i need to change anything?

i added that so the program will not repeat the same random letters.

Thanks.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Programmer
  • 105
  • 1
  • 1
  • 5
  • 1
    Instead of `used.index(r) is None` do `r not in used`. – jdehesa May 14 '20 at 14:29
  • You're not checking if a value in the list is `None`, you're trying to check if the value is in the array. – Barmar May 14 '20 at 14:34
  • Hi Programmer, please familiarise yourself with [asking questions](https://stackoverflow.com/help/how-to-ask) before you write your next question! Enjoy your stay at SO :) – Diggy. May 14 '20 at 14:54

1 Answers1

2

Instead of :

used.index(r) is None

you can directly check for existence via:

r not in used

That showed error as used.index(r) doesn't return None if not found.

Joshua Varghese
  • 5,082
  • 1
  • 13
  • 34