The issue occurs on line 70 - The function is def test().
if sum(characters) > [1]: TypeError: unsupported operand type(s) for +: 'int' and 'list'
For reference, this is a password strength checker.
How do I go about solving this? It seems like the code executes and can count the length of the input as well as add points to the score
import sys
import time
import random
import string # check for certain characters
def ten():
length = 10
chars = string.ascii_letters + string.digits + '!@#$%^&*()'
rnd = random.SystemRandom()
print(''.join(rnd.choice(chars) for i in range(length)))
def fifteen():
length = 15
chars = string.ascii_letters + string.digits + '!@#$%^&*()'
rnd = random.SystemRandom()
print(''.join(rnd.choice(chars) for i in range(length)))
def twenty():
length = 20
chars = string.ascii_letters + string.digits + '!@#$%^&*()'
rnd = random.SystemRandom()
print(''.join(rnd.choice(chars) for i in range(length)))
def twentyfive():
length = 25
chars = string.ascii_letters + string.digits + '!@#$%^&*()'
rnd = random.SystemRandom()
print(''.join(rnd.choice(chars) for i in range(length)))
def test():
# Password Checker
option = input()
upper_case = ([1 if c in string.ascii_uppercase else 0 for c in option])
lower_case = ([1 if c in string.ascii_lowercase else 0 for c in option])
special = ([1 if c in string.punctuation else 0 for c in option])
digits = ([1 if c in string.digits else 0 for c in option])
characters = [upper_case, lower_case, special, digits]
length = len(option)
score = 0
if length > 8:
score += 1
if length > 12:
score += 1
if length > 13:
score += 1
if length > 15:
score += 1
if length > 16:
score += 1
if length > 20:
score += 1
if length > 25:
score += 1
print(f"Password length is {str(length)}, adding {str(score)} points!")
if sum(characters) > 1:
score += 1
if sum(characters) > 2:
score += 1
if sum(characters) > 3:
score += 1
print(f"Password has {str(sum(characters))} different character types, adding {str(sum(characters) - 1)} points! ")
if score < 4:
print(f"Week {str(score)} / 7")
elif score == 4:
print(f"Week {str(score)} / 7")
elif 4 < score < 6:
print(f"Week {str(score)} / 7")
elif score > 6:
print(f"Week {str(score)} / 7")
def quit():
print("This program will now exit...")
time.sleep(2)
sys.exit()
# This is the menu function
def menu():
print("Hello Welcome To My Password Generator!!!")
time.sleep(1)
option = input("""
1: Generate a Random 10 Character Password
2: Generate a Random 15 Character Password
3: Generate a Random 20 Character Password
4: Generate a Random 25 Character Password
5: Test Password Strength
Q: Quit
Please decide on an option from 1, 2, 3, 4, 5 or Q:
""")
if option == "1":
ten()
elif option == "2":
fifteen()
elif option == "3":
twenty()
elif option == "4":
twentyfive()
elif option == "5":
test()
elif option == "Q" or option == "q":
quit()
else:
print("Error, you must enter a valid choice from the above menu")
menu()
menu()