An Interest In:
Web News this Week
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
June 8, 2020 09:10 pm GMT
Original Link: https://dev.to/oxy_oxide/password-generator-using-python-9k6
Password generator using python
Hello, today we will make a simple password generator program using python.
first, we will import random and make 2 new variables:
import random chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-+=!@#$%^&*"length_of_pass = int(input("num of letters:"))
Second, we will define a function that has one parameter called "num",
Inside the function we will make a new empty variable called password , After that we will loop in the range of "num" using "for loop", Inside the loop we will we will use the random module and add the result to password, outside the for loop we will return password:
def pass_generator(num): password = '' for i in range(num): password += random.choice(chars) return password
The last thing we will call the function with the parameter "length_of_pass".
the whole code:
import random chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-+=!@#$%^&*"length_of_pass = int(input("num of letters:"))def pass_generator(num): password = '' for i in range(num): password += random.choice(chars) return passwordprint(pass_generator(length_of_pass))
Don't forget to follow me!
Thanks for reading.
Original Link: https://dev.to/oxy_oxide/password-generator-using-python-9k6
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To