Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Joey Turner 10/7/2017
- Programming Project
- """
- """ VERSION 2 - FIXED THE DEF ON LINE 1 OF THE GET_INPUTS FUNCTION. ALSO,
- HAVE ADDED THE VALIDATE GENDER FUNCTION, AND HAVE REMOVED THE COMMENT
- FROM THE GET_INPUTS() LINE."""
- def get_inputs():
- """ This function will get the user to enter in all the inputs
- needed to run the program, and then return those values to the main
- program.
- """
- firstname = input("Please enter your first name > ")
- # Asks user to enter their first name
- surname = input("Please enter your surname > ")
- # Asks user to enter their surname
- gender = input("Please enter your gender, M or F > ")
- # Asks user to enter their gender
- return firstname, surname, gender
- # Returns the variables 'firstname', 'surname' and 'gender' to the
- # main program.
- def validate_gender(gender):
- """ This function will validate whether the user has entered just ‘M’ or
- ‘F’ for the gender.
- """
- while gender != "M" and gender != "F":
- # Iterates this section of the function until gender is equal to
- # either 'M' or 'F'
- print("Invalid selection of gender.")
- # Notifies the user of their mistake
- gender = input("Please re-enter your gender, M or F > ")
- # Asks the user to re-enter their gender
- return gender
- # Returns the variable 'gender' to the main program.
- def get_user(firstname,surname,gender):
- """ This function will create the username for the user.
- If gender==M, then username is last 3 letters of surname + first 2
- letters of first name
- If gender == F, then username is first 3 letters of first name +
- first 2 letters of surname
- """
- if gender == "F":
- # Checks whether gender = F
- username = firstname[0:3] + surname[0:2]
- # Username is assigned as the first 3 letters of the firstname, and
- # the first 2 letters of the surname
- else:
- # If username is not equal to F (should only be M after the
- # validate_gender function), username is assigned as the last 3
- # letters of the surname and the first 2 letters of the firstname.
- username = surname[-3:] + firstname[0:2]
- return username
- def file_append(username):
- myFile = open('logins.txt','a')
- # The file is opened in append mode, meaning anything written in this
- # procedure will not overwrite current data stored on the file.
- password = "Password123"
- # the variable password is set to 'Password123' so that it can be added
- # to the record.
- record = "Username: " + username + " " + "Password: " + password
- # Combines username and password (along with a spacer) into one variable
- # so it can be appended to the file more easily
- myFile.write(record)
- # The variable 'record' is appended to the file
- myFile.close
- # File is closed so that other programs or the user can now open it.
- firstname, surname, gender = get_inputs()
- validate_gender(gender)
- username = get_user(firstname,surname,gender)
- print(username)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement