0
#random password generator
import random
unified_code = "awertyuiosqpdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890!@#$%^&*()_+"

passlength1=input("how long should your password be")
pass_length2=input("how long should your password be")

def generatrandompaassword():
    length = random.randint(passlength1,pass_length2 )

    password = "" 

    for index in range(length):
        randomCharacter = random.choice(unified_code)
        password = password + randomCharacter



    return password

passworder = generatrandompaassword()
print(passworder)
print("This is your new password")

this won't let me post for some reason what is a comment

this is the code iv made I started python a couple of days ago so I'm pretty new to it

fist I tried putting one-variable and than asking the user for the input and inserting the input into the program and using that to find the length of how long the password should be can get help with this?

3 Answers 3

1

I re-wrote your code. You can read the comments to see what is happening. Essentially, we have a list of characters that will be used in the password. We then ask the user for the length of their password, and convert it to a number. After, we loop through the length and add a random character to the password.

import random
characters = "awertyuiosqpdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890!@#$%^&*()_+"

# Get the length of the password, and cast it to an integer so it can be used in the for loop ahead
length = int(input("how long should your password be? "))

def generatrandompaassword():
    password = ""

    # For every character in the password, get a random character and add that to the password
    for i in range(length):
        password += random.choice(characters)

    return password

# Get the password
password = generatrandompaassword()
print("This is your new password: " + password)
Sign up to request clarification or add additional context in comments.

Comments

0

Code - Your code needed minor changes

# random password generator
import random
unified_code = "awertyuiosqpdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890!@#$%^&*()_+"

pass_length1 = int(input("What should be the min length your password be: "))
pass_length2 = int(input("What should be the max length your password be: "))

def generatrandompaassword():
    length = random.randint(pass_length1, pass_length2 )
    password = "" 
    for index in range(length):
        randomCharacter = random.choice(unified_code)
        password = password + randomCharacter
    return password

passworder = generatrandompaassword()
print(passworder)
print("This is your new password")

The input your receive from the user is of type str, so you need to convert it into int data type.

Output


What should be the min length your password be: 5
What should be the max length your password be: 15
vyA7ROviA
This is your new password

Suggestions:

  • stick to either using _ or camelCasing. pass_length1 and randomCharacter are of two styles.
  • try to keep your functions names easy to understand. use generate_random_password than generatrandompaassword
  • Give some space to = before and after.

Read a bit about python PEP standards to make your code more readable.

Comments

0

enter image description here

It is my way to solve this , I could not get right output from above codes so test my way, good luck

2 Comments

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
Thank you for writing an answer. Please edit and share your code as text. You can edit as often as you like to improve your question. Please do not upload images of code/data/errors. Don't share your e-mail address for follow-up questions. Improve your answer, instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.