Day 5 of #100daysofcode (Life has been busy, in an amazing way, but I skipped some days back on track now though!) today went over using for loops and range functions to iterate over lists of data. Through this project I was able to create a random password generator using amounts of letters/symbols/numbers input by the user.
# Password Generator Project import random letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+'] print("Welcome to the PyPassword Generator!") nr_letters = int(input("How many letters would you like in your password?\n")) nr_symbols = int(input(f"How many symbols would you like?\n")) nr_numbers = int(input(f"How many numbers would you like?\n")) password_list = [] # Iterates through characters in the letter list with a range of 1 and amount of letters chosen + 1 to account for # starting at 0. Then adds the random chosen letters to the password_list. for char in range(1, nr_letters + 1): password_list.append(random.choice(letters)) # Iterates through characters in the symbol list with a range of 1 and amount of symbols chosen + 1 to account for # starting at 0. Then adds the random chosen symbols to the password_list. for symbol in range(1, nr_symbols + 1): password_list.append(random.choice(symbols)) # Iterates through characters in the number list with a range of 1 and amount of numbers chosen + 1 to account for # starting at 0. Then adds the random chosen numbers to the password_list. for number in range(1, nr_numbers + 1): password_list.append(random.choice(numbers)) # Creates a random shuffle of the items in password_list. random.shuffle(password_list) # Sets password to empty string. password = "" # Iterates over the characters in the newly shuffled password_list and adds each character into the empty password # string. for char in password_list: password += char # Prints newly generated randomized password.print(f"Your password is : \n {password}")
as always if you would like to test it out here is the replit link:
https://replit.com/@JamesBarlow3/password-generator-start-1#main.py