Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need some assistance on how to count the special characters, letters and numbers from a generated password in Python. The password generator is fine

I need some assistance on how to count the special characters, letters and numbers from a generated password in Python. The password generator is fine , the only part I'm having issue with is how to count the special characters, letters and numbers from the password.

Here is the code that I have so far:

print('Password Generator') import random

#Function that generates the random password. def password_generator(character_number, letters): # Defining the password length and randomly choosing either the character number or letters. first = random.choice(letters) second = random.choice(character_number) third = random.choice(letters) fourth = random.choice(character_number) fifth = random.choice(letters) sixth = random.choice(character_number) seventh = random.choice(letters) eighth = random.choice(character_number) ninth = random.choice(letters) tenth = random.choice(character_number) #Randomly generating a password and the length. password = first + second + third + fourth+ fifth + sixth + seventh + eighth + ninth + tenth return password

# Defining main function of special characters and letters. def main(): #List of all the numbers and symbols character_number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '#x27;, '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ';', '<', '=', '>', '?', '@', '[', ']', '}', '{', '^', '~', '#', '`', ':']

#List of all uppercase and lowercase letters. letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'M', 'N', 'O', 'p', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

#Loop until the user wants to exit the program. while(True): print(' Select') print('1.Generate Password') print('2.Exit The program') choice = input() if(choice.isnumeric() == True): if(int(choice) == 1): generated_password = password_generator(character_number, letters) #Display the password print(' Your Password is:', generated_password) elif(int(choice) == 2): print(' End of the program') exit() else: print('Invalid Selection') else: print('Invalid Selection')

#Counting the number of alphabets, digits, and special characters from the generated password. string = generated_password alphabets=0 digits=0 specialChars=0 #checks for each character in the string for i in string: #if character of the string is an alphabet if i.isalpha(): alphabets+=1 #if character of the string is a digit elif i.isdigit(): digits+=1 else: #if character of the string is a special character specialChars+=1 print("alphabets =",alphabets,"digits =",digits,"specialChars =",specialChars)

# Using the special variable # __name__ if __name__=="__main__": main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Foundations of Financial Management

Authors: Stanley Block, Geoffrey Hirt, Bartley Danielsen, Doug Short, Michael Perretta

10th Canadian edition

1259261018, 1259261015, 978-1259024979

More Books

Students also viewed these Programming questions