Question

In: Computer Science

I have to write a random password generator in Python 3 and im having some trouble...

I have to write a random password generator in Python 3 and im having some trouble writing the code and i dont really know where to start. The prompt goes as such:

The problem in this assignment is to write a Python program that uses functions to build (several options of) passwords for the user. More specifically, your program will do the following:

1. Prompt the user for the length of the password to be generated. Call this length lenP.

2. The password can be made of: (a) lower case letters (nLower) (b) upper case letters (nUpper) (c) digits (between 0 and 9) (nDigits) (d) one special character from this collection: !, @, #, $, %, *, = So the program must also prompt the user for how many lower case letters, how many upper case letters, and how many digits, they want in the password. These values will be stored in nLower, nUpper, and nDigits, respectively. There will be only and exactly one special character on every password.

3. First make sure that lenP = nLower + nUpper + nDigits + 1. In other words that all those characters will fit in a password of length lenP.

4. Using the numbers given by the user, the program must pick randomly: nLower lower case letters from the collection of those letters, nUpper from the collection of all the upper case letters, and nDigits from the ten digits.

5. Pick randomly one special character from the seven characters listed above.

6. Build a password string with all the lower, upper case letters, digits, and the special character, picked randomly in the steps 4 and 5 above, by placing each of those “letters”, numbers, and special character in a random place on the password.

7. After builiding ONE password in the above fashion, shuffle all the characters in the password to produce three other passwords, all with the same characters but in different orders.

8. The final output to the user is all four passwords produced in all the steps above. The program should only print the prompts and interaction with the user and these four passwords with a message to the user showing them, nothing else should be printed by this program.

I must also include:

• A function called pickSome(n, s) Given the number n, this function will randomly select n characters from the string s and will return them in another string. For example, to pick 2 upper case letters from all the upper case letters, you should call this function as: pickSome(2,’ABCDEFGHIJKLMNOPQRSTUVWXYZ’), the function will return a string with the two upper case letters selected randomly. For example, that call could return LC as a string.

• A function called putTogether(forPasswd) the function takes a string of letters (upper and lower case), digits, and one special character and will place each of the characters in the string in a random location on a new string. It returns the new string built by placing the characters in the string passed as argument in random order. For example, when this function is called as: putTogether(’aceLP29=’) it could return the following new string: 2aLce9P=

• A function called shuffle(passwd) which given the string passwd, it will randomly reorder the characters in that string and return the new string

there is so much to this and i dont really know where to start

Solutions

Expert Solution

import random

def pickSome(n,s):

  #convert string to list

  l = list(s)

  # In-place shuffle

  random.shuffle(l)

  # Take the first 2 elements of the now randomized array

  m=l[0:n]

  #convert it to string again

  result = ''.join(m)

  return result

def putTogether(s):

  l=list(s)

  # In-place shuffle

  random.shuffle(l)

  result = ''.join(l)

  return result

def shuffle(s):

  l=list(s)

  pr=[]

  

  for i in range (0,3):

    random.shuffle(l)

    result = ''.join(l)

    print(result)

print("Enter length of the password")

lenP=int(input())

print("Enter number of lower case letters in the password")

nLower=int(input())

print("Enter number of upper case letters in the password")

nUpper=int(input())

print("Enter number of digits in the password")

nDigit=int(input())

if(lenP==nLower+nUpper+nDigit+1):

  pas=''

  pas+=pickSome(nUpper, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')

  pas+=pickSome(nLower, 'abcdefghijklmnopqrstuvwxyz')

  pas+=pickSome(nDigit, '01234567890')

  pas+=pickSome(1, '!@#$%*=')

  print("Your passwords:")

  print(putTogether(pas))

  shuffle(pas)


Related Solutions

Having some trouble with this python question. An answer would be greatly appreciated! #Write a function...
Having some trouble with this python question. An answer would be greatly appreciated! #Write a function called are_anagrams. The function should #have two parameters, a pair of strings. The function should #return True if the strings are anagrams of one another, #False if they are not. # #Two strings are considered anagrams if they have only the #same letters, as well as the same count of each letter. For #this problem, you should ignore spaces and capitalization. # #So, for...
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
I am currently having trouble understanding/finding the errors in this python code. I was told that...
I am currently having trouble understanding/finding the errors in this python code. I was told that there are 5 errors to fix. Code: #!/usr/bin/env python3 choice = "y" while choice == "y": # get monthly investment monthly_investment = float(input(f"Enter monthly investment (0-1000):\t")) if not(monthly_investment > 0 and monthly_investment <= 100): print(f"Entry must be greater than 0 and less than or equal to 1000. " "Please start over.")) #Error 1 extra ")" continue # get yearly interest rate yearly_interest_rate = float(input(f"Enter...
hey im having trouble with this Use Excel to find the Standard Normal Probability for the...
hey im having trouble with this Use Excel to find the Standard Normal Probability for the following questions. Don't forget to sketch the normal distribution and shade the required area. a) What is the area under the standard normal curve to the left of z = 0.89? (4dp) Answer b) What is the area under the standard normal curve between z = -0.89 and z = 1.63? (4dp) Answer c) What is the z-value that gives the right hand tail...
I just wrote Python code to solve this problem: Write a generator that will return a...
I just wrote Python code to solve this problem: Write a generator that will return a sequence of month names. Thus gen = next_month('October') creates a generator that generates the strings 'November', 'December', 'January' and so on. If the caller supplies an illegal month name, your function should raise a ValueError exception with text explaining the problem. Here is my code: month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] def next_month(name: str) -> str:...
Im having trouble turning my words and calculations into tables and graphs for my research methods...
Im having trouble turning my words and calculations into tables and graphs for my research methods paper. I need 2 tables and 1 graph. Table 1 - should show that out of 17,425 respondents 43% resported being in business for 3+ years. 33% reported being in business for 1-2 years and 24% respondents being on business for 0-1 years Table 2 - should show marketing method preference. 43% respondent with both online and relationship marketing methods. the 33% group respondent...
Hello, Im having trouble understanding the graphing/chart section of this lesson. Is there anyone who can...
Hello, Im having trouble understanding the graphing/chart section of this lesson. Is there anyone who can help me understand? Goods A B C D E F Capital 5 4 3 2 1 0 Consumer 0 5 9 12 14 15 (presentation as a table rather than as a graph) 1. Using the above PPTable, if the economy is producing at alternative D, the opportunity cost of producing one more unit of capital is A. 1 unit of consumer goods. B....
I have having trouble with data table 4 and i would like someone to double check...
I have having trouble with data table 4 and i would like someone to double check my work on the other tables. NaHCO3(s) + HC2H3O2(aq) → C2H3O2Na(aq) +H2CO3(aq) H2CO3(aq)→ H2O(l) +CO2(g) Note: 5 mL of 5% vinegar contains 0.25 mL of HC2H3O2 with a density of 1.0 g/mL which equals 0.25 g HC2H3O2. Data Table 4                           Limiting Reactant            Theoretical yield of CO2(moles)    Theoretical yield of CO2(g) Reaction 1        NaHCO2 Reaction 2        NaHCO2 Reaction 3       HC2H3O2 Reaction 4        HC2H3O2 Data...
Im having trouble making nursing diagnosis for PTSd , anyone can give idea. My pt is...
Im having trouble making nursing diagnosis for PTSd , anyone can give idea. My pt is 26 yo had car accident since then shes distressed by the accident, social interaction changed, unable to handle work , she experienced flashback and have phobia against car. She experienced self destructive behavior and experienced sleep dosturbances
I was able to calculate (a) but I am having trouble with the calculations of (b)....
I was able to calculate (a) but I am having trouble with the calculations of (b). Thanks! The following are New York closing rates for A$/US$ and $/£:                                     A$/$ = 1.5150;               $/£ = $1.2950             (a) Calculate the cross rate for £ in terms of A$ (A$/£).             (b) If £ is trading at A$1.95/£ in London (cross market) on the same day, is there an arbitrage opportunity?  If so, show how arbitrageurs with £ could profit from this opportunity and calculate the arbitrage...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT