Question: i need help fixing this code: Im not getting the right output or any at all. import string # DO NOT EDIT THIS LINE import

i need help fixing this code: Im not getting the right output or any at all. import string # DO NOT EDIT THIS LINE
import random # DO NOT EDIT THIS LINE
# PART A
# ======
# You will use your code from Problem 1 to create a new function with the
# following signature:
#
# generatePassword(length, uppercase, lowercase, numeric)
#
# This method will generate a password of a given length using the user's
# choice of uppercase, lowercase, and numeric characters and
# return the new password. You can accomplish this by creating a variable
# to hold a new password and creating a loop to randomly select a character
# and add it to the new variable, looping until the length requirement
# is met. (Note: you can also use the join/for syntax as an alternative).
#
# This method will then return the new password
def generatePassword(length, uppercase, lowercase, numeric):
chars =""
if uppercase:
chars += string.ascii_uppercase
if lowercase:
chars += string.ascii_lowercase
if numeric:
chars += string.digits
if not chars:
return ""
password =''.join(random.choice(chars) for _ in range(length))
return password
def main(): # DO NOT EDIT THIS LINE
print("Welcome to the Password Generator")
# PART B
# ======
# You will ask the user if they want to include uppercase, lowercase,
# and numeric characters as part of the output character set.
#
# You will do this by asking the following questions:
#
# How long do you want your password to be?
# Do you want to include UPPERCASE characters? (1= YES, 0= NO)
# Do you want to include lowercase characters? (1= YES, 0= NO)
# Do you want to include numeric characters? (1= YES, 0= NO)
#
# Save each response into the respective variables:
#
# length_response
# uppercase_response
# lowercase_response
# numeric_response
#
# Only ask the four questions (use four input statements). Do not include
# any more print statements or input statements.
#
# Once you gather this information, pass it to the generatePassword function
# and display the result.
length_response = int(input("How long do you want your password to be?"))
uppercase_response = int(input("Do you want to include UPPERCASE characters? (1= YES, 0= NO)"))
lowercase_response = int(input("Do you want to include lowercase characters? (1= YES, 0= NO)"))
numeric_response = int(input("Do you want to include numeric characters? (1= YES, 0= NO)"))
password = generatePassword(
length_response,
bool(uppercase_response),
bool(lowercase_response),
bool(numeric_response),
)
if password:
print("generated password:", password)
else:
print("No valid character set selected for passwprd generation.")
return # DO NOT EDIT THIS LINE
if __name__=="__main__": # DO NOT EDIT THIS LINE
main()# DO NOT EDIT THIS LINE

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!