import random
import stringdef generate_password(length, include_digits=True, include_symbols=True):
characters = string.ascii_letters
if include_digits:
characters += string.digits
if include_symbols:
characters += string.punctuationpassword = ”.join(random.choice(characters) for _ in range(length))
return passworddef main():
print(“Welcome to the Random Password Generator!”)
print(“—————————————-“)length = int(input(“Enter the desired length of the password: “))
include_digits = input(“Include digits? (y/n): “).lower() == ‘y’
include_symbols = input(“Include symbols? (y/n): “).lower() == ‘y’password = generate_password(length, include_digits, include_symbols)
print(“Your randomly generated password is: ” + password)if __name__ == ‘__main__’:
main()In this program, the
generate_password
function generates a random password based on the provided length and user preferences. It uses therandom
module to select characters randomly from a string that includes letters, digits, and symbols. Themain
function prompts the user to input the desired password length, whether to include digits, and whether to include symbols. It then calls thegenerate_password
function with the user’s preferences and prints the generated password.
When you run the program, it will ask for the password length, whether to include digits, and whether to include symbols. After gathering the necessary information, it will generate a random password and display it on the screen. You can customize the program further by adding error handling or incorporating additional password complexity rules.