1

I'm just making a name generator for practice. I've tried removing the input function but it still doesn't give any value. Its a small code:

import random
l = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','y','x','z']

name = []

ui = input()

if ui == 'gen':

    while len(name) != 4 or 5 or 6 or 7:
        name.append(random.choice(l))
name = ''.join(name)

print(name)

I wanted it to print a name that contains 4,5,6 or 7 letters. But it doesn't prints anything.

  • the reason of `it doesn't prints anything.` is because it never can get out of `while len(name) != 4 or 5 or 6 or 7:`, because you use `or` here, `or 5 or 6 or 7` will always true. you can write like that: `name_len = random.choice([4, 5, 6, 7]); while len(name) != name_len:` – recnac Apr 07 '19 at 08:08
  • by the way, you can `import string; random.choice(string.ascii_lowercase)` instead of input l='a'-'z' by hand. – recnac Apr 07 '19 at 08:20
  • I think that's high level for me as I don't understand what it does but I will catch up to it real soon! Thanks! @recnac – Vansh Kalra Apr 07 '19 at 12:33
  • just keep studying day by day, you will be better. – recnac Apr 07 '19 at 12:34

0 Answers0