Python Programming Challenge #7 - Generating Usernames & Passwords

Free Video Tutorial and Guide

In this video, we'll take on another Python Programming Challenge and create a program that generates usernames and passwords. Tune in to learn how!

Starting File - https://www.dropbox.com/s/nfiw8otzw0fe2ww/Noble%20Desktop%20Python%20Challenges%20Starting%20Files.ipynb?dl=1

Final File - https://www.dropbox.com/s/7zemrs0amnqcvcu/Noble%20Desktop%20Python%20Challenges%20Final%20Files.ipynb?dl=1

Video Transcription

We will write a function called 'assign usernames and passwords' which takes a list of first and last names as input (names list). The function will loop through the names list, creating a dictionary for each full name with four keys: 'F name' (with the first name), 'L name' (with the last name), 'user' (another key with a username composed of the first name to lower case plus the first letter of the last name to uppercase) and 'password' (a key with a password value composed of the first name backwards with backwards capitalization and then a special character according to the following rules.

An ampersand if the two names are equal length and start with the same letter, a percent sign if the names are equal length but do not start with the same letter, a dollar sign if the name start with the same letter but are not equal length and a pound sign if the names are different lengths and start with different letters.

There is also a number based on the length of the first name: if the first name length is less than or equal to last name length, the number is the square of the length of the first name; if the first name length is longer than the last name, the number is the square of the difference in name length. The function will store the resulting data in a dictionary, accumulate the dictionaries in a new list and return the new list of dictionaries and each user's dictionary.

The function we are creating is to take a list of names and a list of full names, split them into first and last name and use them to create a username and password for each person. The username will consist of the first name in lowercase followed by the first letter of the last name in uppercase and the sum of the lengths of the two strings.

The password will begin as the first name backwards, with a special character added based on the length of the first and last name. If the length of the first name is equal to the length of the last name and the first letter of the first name is equal to the first letter of the last name, the password will be plus an ampersand. If the first letters are the same but the lengths are different, the password will be plus a percent sign.

If the first letters are different and the lengths are different, the password will be plus a dollar sign. Lastly, the number to be concatenated onto the password will be the sum of the strings if the length of the first name is less than or equal to the length of the last name, or the length of the first name minus the length of the last name squared if the length of the first name is greater than the length of the last name.

Once the function is complete, it will return a list of dictionaries containing the four key-value pairs of the first name, last name, username, and password.

How to Learn Python

Master Python with hands-on training. Python is a popular object-oriented programming language used for data science, machine learning, and web development. 

Yelp Facebook LinkedIn YouTube Twitter Instagram