Advertisement
joeyturner123

PProject v3

Jul 10th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.13 KB | None | 0 0
  1. """ Joey Turner 10/7/2017
  2.    Programming Project
  3. """
  4.  
  5. """ VERSION 2 - FIXED THE DEF ON LINE 1 OF THE GET_INPUTS FUNCTION. ALSO,
  6.    HAVE ADDED THE VALIDATE GENDER FUNCTION, AND HAVE REMOVED THE COMMENT
  7.    FROM THE GET_INPUTS() LINE."""
  8.  
  9.  
  10. def get_inputs():
  11.     """ This function will get the user to enter in all the inputs
  12.        needed to run the program, and then return those values to the main
  13.        program.
  14.    """
  15.    
  16.     firstname = input("Please enter your first name > ")
  17.         # Asks user to enter their first name
  18.     surname = input("Please enter your surname > ")
  19.         # Asks user to enter their surname
  20.     gender = input("Please enter your gender, M or F > ")
  21.         # Asks user to enter their gender
  22.     return firstname, surname, gender
  23.         # Returns the variables 'firstname', 'surname' and 'gender' to the
  24.         # main program.
  25.  
  26.  
  27.  
  28. def validate_gender(gender):
  29.     """ This function will validate whether the user has entered just ‘M’ or
  30.        â€˜F’ for the gender.
  31.    """
  32.     while gender != "M" and gender != "F":
  33.         # Iterates this section of the function until gender is equal to
  34.         # either 'M' or 'F'
  35.         print("Invalid selection of gender.")
  36.             # Notifies the user of their mistake
  37.         gender = input("Please re-enter your gender, M or F > ")
  38.             # Asks the user to re-enter their gender
  39.     return gender
  40.         # Returns the variable 'gender' to the main program.
  41.  
  42.  
  43.  
  44. def get_user(firstname,surname,gender):
  45.     """ This function will create the username for the user.
  46.  
  47.        If gender==M, then username is last 3 letters of surname + first 2
  48.            letters of first name
  49.        If gender == F, then username is first 3 letters of first name +
  50.            first 2 letters of surname
  51.    """
  52.  
  53.     if gender == "F":
  54.         # Checks whether gender = F
  55.         username = firstname[0:3] + surname[0:2]
  56.         # Username is assigned as the first 3 letters of the firstname, and
  57.         # the first 2 letters of the surname
  58.     else:
  59.         # If username is not equal to F (should only be M after the
  60.         # validate_gender function), username is assigned as the last 3
  61.         # letters of the surname and the first 2 letters of the firstname.
  62.         username = surname[-3:] + firstname[0:2]
  63.     return username
  64.  
  65. def file_append(username):
  66.   myFile = open('logins.txt','a')
  67.     # The file is opened in append mode, meaning anything written in this
  68.     # procedure will not overwrite current data stored on the file.
  69.   password = "Password123"
  70.     # the variable password is set to 'Password123' so that it can be added
  71.     # to the record.
  72.   record = "Username: " + username + " " + "Password: " + password
  73.     # Combines username and password (along with a spacer) into one variable
  74.     # so it can be appended to the file more easily
  75.   myFile.write(record)
  76.     # The variable 'record' is appended to the file
  77.   myFile.close
  78.     # File is closed so that other programs or the user can now open it.
  79.  
  80. firstname, surname, gender = get_inputs()
  81. validate_gender(gender)
  82. username = get_user(firstname,surname,gender)
  83. print(username)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement