I am creating code for a class project and part of it is that I need to find out if a set of randomly selected key words has a collective character length between two desired values. The issue I'm having is that Python stops executing as soon as it reaches the loop section. here is the whole code, I am having trouble with the part after the second user input.
import random #allows us to generate random numbers elsewhere in the code
set1=[] # creates empty sets
print("type genPassword() to initiate the program")
def genPassword():
print("Answer the following questions in order. What is your first pet’s name? What is your favorite word? What was your first car? What city/town were you born in? What was the name of your first partner? dont forget to press enter after each word, no spaces.")
for c in range(0,5): #allows the user to add elements to the list, each element has to be on a seperate line
ele=input()
set1.append(ele)
print(set1)#displays the current set, currently used for debugging purposes, making sure the code works
minlen=int(input("what is the minimum length you would like the password to be?: "))
maxlen=int(input("what is the max length you would like your password to be? (must be more than the shortest word you input in previous section): "))
passlen=0
while minlen >= passlen >= maxlen:
set2=[] #empties set 2
amnt = random.randint (1,5) #selects a random number for the anount of keywords to use
for f in range(0,amnt):
keys=random.sample(set1,1) #selects a random key word
set2.append(keys) #adds word to set 2
print(set2)#shows the words it chose
set_amnt=len(set2) #how many words in the set
iteration=0
string_len=0
for i in range(0,set_amnt):
word_len=len(set2[iteration][0]) #takes the length of each word and adds it to the lenght of the whole string
iteration=iteration+1
string_len=string_len+word_len
print(string_len) #shows how long the string is (how many letters it is total)
passlen=string_len
I tried switching the loop types and adjusting where variables are in the code, but neither of those things worked and I cant think of what else to try to make it work. I even took the section out of a looping statement and it works then but it for some reason is having trouble with the loop. I expect it to select a random amount of words and tell me how long the whole string is and what words it picked out of a set of five words and then if the string is too long or too short it repicks and does it again and again until the string is within the accepted range of values for character length, printing the length and what words it chose each iteration.