Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
1 . In this lab you will write a Python script that will generate random passwords from the given list variable many _ words _
In this lab you will write a Python script that will generate random passwords from the given list variable manywordslist. Your script should start by assigning a variable usernumber to a value to be entered by the user. This number should be validated and must be between and inclusive. This value would refer to the number of words to be chosen randomly from the list variable manywordslist. Depending on the value of usernumber, your code should randomly choose that number of words from the manywordslist. Lastly, your script should concatenate these words into one string to create the password and print it on the screen. Hint: You will need random to be imported. You are free to explore its methods. Next, define the following two functions in your code: repwithupper This function takes a string as its only parameter and returns a new string value. The function should create the new string value by replacing a character randomly chosen inside the given parameter with its uppercase version eg a A In your modified script, you will call this function by passing the password created in Question# as the argument value. swapletters This function takes a string as its only parameter and returns a new string value. The function should create the new string value by swapping the first two characters of the given parameter with the ones in the last two eg Password rdsswoPa In your modified script, you will call this function by passing the password returned from repwithupper function as the argument value. Now, modify your script for Question# in the following manner: Using your answer to Question# create the initial password; then using this password as the argument value to the repwithupper function create a new password; finally using this new password as the argument value to the swapletters function create the final version of the password. Your modified script should print both the initial and the final versions of the password created. SAMPLE OUTPUT bold parts are entered by user: Please enter a value from to for the number of words: Invalid value! Please enter a value from to for the number of words: Invalid value! Please enter a value from to for the number of words: Initial password: pythonsurelemonunix Final version of the password: ixthonsuRelemonunpy In this last question, add your code the following: Open a file named storetxt in write mode. Write your last password from the previous question. The file should have only one line, which is the password you have generated.
In this lab you will write a Python script that will generate random passwords from the given list
variable manywordslist. Your script should start by assigning a variable usernumber to a value
to be entered by the user. This number should be validated and must be between and inclusive.
This value would refer to the number of words to be chosen randomly from the list variable
manywordslist. Depending on the value of usernumber, your code should randomly choose
that number of words from the manywordslist. Lastly, your script should concatenate these words
into one string to create the password and print it on the screen.
Hint: You will need random to be imported. You are free to explore its methods.
Next, define the following two functions in your code:
repwithupper This function takes a string as its only parameter and returns a new string value.
The function should create the new string value by replacing a character randomly chosen inside the
given parameter with its uppercase version eg a A In your modified script, you will call this
function by passing the password created in Question# as the argument value.
swapletters This function takes a string as its only parameter and returns a new string value.
The function should create the new string value by swapping the first two characters of the given
parameter with the ones in the last two eg Password rdsswoPa In your modified script, you
will call this function by passing the password returned from repwithupper function as the
argument value.
Now, modify your script for Question# in the following manner: Using your answer to Question#
create the initial password; then using this password as the argument value to the repwithupper
function create a new password; finally using this new password as the argument value to the
swapletters function create the final version of the password. Your modified script should print
both the initial and the final versions of the password created.
SAMPLE OUTPUT bold parts are entered by user:
Please enter a value from to for the number of words:
Invalid value!
Please enter a value from to for the number of words:
Invalid value!
Please enter a value from to for the number of words:
Initial password: pythonsurelemonunix
Final version of the password: ixthonsuRelemonunpy
In this last question, add your code the following: Open a file named storetxt in write mode.
Write your last password from the previous question. The file should have only one line, which is the
password you have generated.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started