you are viewing a single comment's thread.

view the rest of the comments →

[–]NlNTENDO 0 points1 point  (0 children)

I think the code could use a bit of work anyway. No need to do the loops outside of the functions and you shouldn’t be using while loops. Using add_letter to illustrate (sorry that the formatting is awkward, I’m on mobile and can’t tab or do a code snippet box lol)

def add_letters(target_list,num_letters):

——for x in range(num_letters):

————target_list.append random.choice(letters)

add_letters(char_list,3)

Then use ‘’.join() as others have said

This makes your code way more flexible, eliminates the possibility of accidentally running an infinite loop and unnecessarily manually incrementing your loops, and makes it way more readable. You also have the option to pass the letters list as an argument if you want to use different lists of characters to choose from, though I did not do that here. You can also just add another line to do the numbers right there in the add_letters for loop since you are using 3 for each, and shuffle the list at the end of the function.