Password Strength Visualizer

import string

def analyze_password(password):
"""Analyze the strength of the password."""
length = len(password)
has_upper = any(c.isupper() for c in password)
has_lower = any(c.islower() for c in password)
has_digit = any(c.isdigit() for c in password)
has_special = any(c in string.punctuation for c in password)

# Base score increments
score = 0
if length >= 12:
score += 3
elif length >= 8:
score += 2
elif length > 0:
score += 1

if has_upper:
score += 2
if has_lower:
score += 2
if has_digit:
score += 2
if has_special:
score += 2

return min(score, 10) # Ensure score does not exceed 10

def display_strength(score):
"""Display password strength based on the score."""
strength_levels = [
"Very Weak", "Weak", "Fair", "Moderate", "Strong", "Very Strong", "Excellent"
]
strength = strength_levels[score // 2] # Adjusting for 0-10 scale

print("\nPassword Strength Analysis:")
print(f"Strength Level: {strength}")
print("Visual Representation: " + "█" * score + "░" * (10 - score))

def main():
print("Welcome to the Password Strength Visualizer!")
password = input("Enter a password to analyze: ")
score = analyze_password(password)
display_strength(score)

if __name__ == "__main__":
main()