0

I have attempted to create something that resembles a password generator, the first part being a word and the second part being a 2-digit number. However, I receive an index error whenever I run this program. Any solutions?


import urllib.request
import random



word_url = "https://donyinc.weebly.com/uploads/4/2/1/7/42178775/part1.txt"
response = urllib.request.urlopen(word_url)
long_txt = response.read().decode()
words = long_txt.splitlines()

upper_words = [word for word in words if word[0].isupper()]
name_words  = [word for word in upper_words if not word.isupper()]
one_name = ' '.join([name_words[random.randint(0, len(name_words))] for i in range(1)])


def rand_name():
   name = ' '.join([name_words[random.randint(0, len(name_words))] for i in range(1)])
   return name


for n in range(10):
    name = rand_name()

#part 2

alphabet = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%^&*"
no_length = 2
myno = ""

for i in range(no_length):
    next_index = random.randrange(len(alphabet))
    myno = myno + alphabet[next_index]

print(name)+(no)

input('Press ENTER to exit')

4

1 に答える 1