Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m having a problem to do this code. Could you please help me with it This cod

ID: 3799874 • Letter: I

Question

I'm having a problem to do this code. Could you please help me with it

This code must be in python 3 and include python documents.

When creating a password we normally have to follow a given set of rules. Write a program that will ask the user for a password and check if the password satisfies the following rules. The password must:

1. Be at least 8 characters in length

2. Contain at least 1 lowercase and 1 uppercase letter

3. Contain at least 1 special character (!@# $ % & *)

4. Contain at least 1 number (0-9) Your program must meet the following specifications:

1. Get a password as input from the user.

2. Check that the password satisfies the rules given above.

3. Document the program using Python comments.

4. The algorithm pseudocode should address how the code will know if all conditions are met.

2 Helpful Programming Tools

2.1 String Constants

The string class contains constants that will be very helpful for this assignment. These constants include:

• string.ascii lowercase - The lowercase letters ‘abcdefghijklmnopqrstuvwxyz’.

• string.ascii uppercase - The uppercase letters ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’.

• string.digits - The string ‘0123456789’.

In order to use these constants, you must have the line import string at the beginning of your Python (.py) file.

2.2 The in Operator

The in operator allows us to determine if one string is a substring of the other.

str1 in str2

Example 1: Is the character ch a vowel?

def main():

vowels = "aeiou"

ch = input("Enter a character: ")

if ch in vowels:

print(ch, "is a vowel")

else:

print(ch, "is a consonant")

main()

Example 2: Is the character ch a number (0-9)? import string

def main():

ch = input("Enter a character: ")

if ch in string.digits:

print(ch, "is a digit")

else:

print(ch, "is not a digit")

main()

3 Sample Output

Here are a few sample runs of the program.

>>> main()

Welcome to the password creator!

Your password must:

Be at least 8 characters in length

Contain at least 1 lowercase and 1 uppercase letter

Contain at least 1 special character (!@#$%&*)

Contain at least 1 number (0-9)

Please select a password: hK91@

hK91@ is not a valid password! 2

>>> main()

Welcome to the password creator!

Your password must:

Be at least 8 characters in length

Contain at least 1 lowercase and 1 uppercase letter

Contain at least 1 special character (!@#$%&*)

Contain at least 1 number (0-9)

Please select a password: hP394!@s

hP394!@s is a valid password!

>>> main()

Welcome to the password creator!

Your password must:

Be at least 8 characters in length

Contain at least 1 lowercase and 1 uppercase letter

Contain at least 1 special character (!@#$%&*)

Contain at least 1 number (0-9)

Please select a password: hello!09

hello!09 is not a valid password!

Explanation / Answer

import string

def isValid(password):
   if len(password) < 8:
       return False
   lowercase_count = 0
   uppercase_count = 0
   special_count = 0
   digit_count = 0
   for i in range(0, len(password)):
       if password[i] in string.ascii_lowercase:
           lowercase_count = lowercase_count + 1
       if password[i] in string.ascii_uppercase:
           uppercase_count = uppercase_count + 1
       if password[i] in string.digits:
           digit_count = digit_count + 1
       if password[i] in '!@#$%&*':
           special_count = special_count + 1
   if lowercase_count < 1 or uppercase_count < 1 or digit_count < 1 or special_count < 1:
       return False
   else:
       return True


def main():
   print 'Welcome to the password creator!'
   print 'Your password must:'
   print 'Be at least 8 characters in length'
   print 'Contain at least 1 lowercase and 1 uppercase letter'
   print 'Contain at least 1 special character (!@#$%&*)'
   print 'Contain at least 1 number (0-9)'
   password = raw_input ('Please select a password: ')
   if isValid(password):
       print password + ' is a valid password!'
   else:
       print password + ' is not a valid password!'

main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote