232k views
2 votes
7.2 Code Practice: Question 2

Instructions
Write a program to generate passwords. The program should ask the user for a phrase and number, and then create the password based on our special algorithm. The algorithm to create the password is as follows: If the user’s input word is less than 8 characters, output Password not long enough. If the user’s input word is greater than or equal to 8 characters, do the following: Replace e with @ Replace s or S with $ Replace t or T with + Capitalize the word and add the number to the end.
Sample Run 1 Enter your word: zebras Enter a number: 62
Password not long enough.
Sample Run 2 Enter your word: newyorkcity Enter a number: 892
Password: N@wyorkci+y892

User GaRRaPeTa
by
5.0k points

2 Answers

3 votes

Answer:

w = input("input your word: ")

numeric = input("input your number: ")

if len(w) < 8:

print("Password not long enough")

else:

w = w.replace("t", "+")

w = w.replace("T", "+")

w = w.replace("s" , "$")

w = w.replace("e", "symbol of at")

w = w.replace("S" , "$")

w = w.capitalize( )

print("Your password: " + w + numeric)

Step-by-step explanation:

The code is written in python. Use python 3 software not python 2.

w = input("input your word: ")

This code prompt the user to input a word.

numeric = input("input your number: ")

This code prompt the user to input a number.

if len(w) < 8:

This code check if the length of the word inputted is less than 8

print("Password not long enough")

This code prints Password not long enough if the word length is less than 8

else:

otherwise

w = w.replace("t", "+")

The code replaces t with +

w = w.replace("T", "+")

The code replaces T with +

w = w.replace("s" , "$")

The code replaces s with $

w = w.replace("e", "symbol of at")

The code replaces e with symbol of at

w = w.replace("S" , "$")

The code replaces S with $

w = w.capitalize()

The code capitalize your first letter in the word inputted

print("Your password: " + w + numeric)

The code prints the final word plus the number to form the required password.

Note that the symbol of "at " cannot be used on this platform so insert the symbol accordingly.

User Marcz
by
5.5k points
7 votes

Answer:

Following is given the solution to the question. I hope it will help you a lot!

Step-by-step explanation:

7.2 Code Practice: Question 2 Instructions Write a program to generate passwords. The-example-1
User Arcao
by
5.2k points