I have an issue with my password generator where it loops and reprints the password for each new symbol letter or number I just want it to print the set number for example 10 if someone types 10. Here is my code in python,
import random
length = input ("how long do you want your password to be?")
password = ''
lowercase = 'abcdefghijklmnopqrstuvwxyz'
for i in range(int()):
randChar = random.choice(lowercase)
password = password + randChar
print("Weak Password: " + password)
password2 = ''
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in range(int(length)):
randChar = random.choice(lowercase + uppercase)
password2 = password2 + randChar
print("Moderate Password: " + password2)
password3 = ''
number = '123456789'
for i in range(int(length)):
randChar = random.choice (lowercase + uppercase + number)
password3 = password3 + randChar
print("Strong Password "+ password3)
password4 = ''
symbol = '~!@#$%%^&*":?><+/\|,."'
for i in range(int(length)):
randChar = random.choice (lowercase + uppercase+ number + symbol)
password4 = password4 + randChar
print("Stronger Password "+ password4)
password5 = ''
russian = 'ийнжмвеядсбзхртхоы'
for i in range(int(length)):
randChar = random.choice (lowercase + uppercase + number + symbol + russian)
password5 = password5 + randChar
print("Strongest Password" + password5)
password6 = ''
arabic = 'ضصثقفغعهخحجدشسيبلاتنمكطئءؤرلاىةوزظ'
for i in range(int(length)):
randChar = random.choice (lowercase + uppercase + number + symbol + russian + arabic)
password6 = password6 + randChar
print("The Strongest Password Of All " + password6)
In the first for loop, you might have meant: for i in range(int(length))
[ you forgot the argument for int() ].
Also, I think your problem lies in the indentation of the print() statement.
You should put it after the for loop, like so:
for i in range(len(length)):
randomChar = random.choice(lowercase)
password = password + randomChar
# END INDENTATION
print(password)
It should have three characters if you specified a length of 3. Is that not what’s happening? Please, could you give me the link to your repl? (just copy and paste the URL that you see when editing your repl)
You forgot to make the input a number. The way it is right now, if you input 99, the length will actually be 2 because it’s a string made of two characters. To solve this, wrap the input in an int(), like so length = int(input(“Enter…”))
Edit, to make it more clear: input() returns a string. len(“someString”) returns the number of characters in the string, so len(“Hello”) will return 5.
Because your input is treated as a string, if you input 99, it will be “converted” into a string by the input function, and later in len(length), it will be interpreted as len(“99”). Because ”99” is a string, its length will be the number of characters in it, in this case 2