Advertisement
Guest User

profile

a guest
Jan 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.54 KB | None | 0 0
  1.  
  2.  
  3. class Profile:
  4.     def __init__(self, first_name, last_name):
  5.         self.first_name = first_name
  6.         self.last_name = last_name
  7.         self.dob = []
  8.         # create a dob dict with keys date, month, yeat
  9.         self.age = 0
  10.         self.legal = True
  11.         self.email_pri = 'primary email'
  12.         self.email_sec = 'No secondary email entered'
  13.  
  14.     def age_calc(self):
  15.         self.dob = input("Enter your date of birth (MM/DD/YYYY): ").split('/')
  16.         new_age = (2018 - int(self.dob[2]))
  17.         if new_age >= 18:
  18.             self.age = new_age
  19.         else:
  20.             print("You need to be 18 or older to create a profile.")
  21.             self.legal = False
  22.             if self.legal == False:
  23.                 pass
  24.  
  25.     def email_gen(self):
  26.         new_email = input("Enter your primary email address: ")
  27.         if '@' in new_email:
  28.             self.email_pri = new_email
  29.         else:
  30.             new_email = input("Please enter a valid email address: ")
  31.        
  32.         new_email = input("Enter a secondary email address, or type n to continue: ")
  33.         if '@' in new_email:
  34.             self.email_sec = new_email
  35.         elif new_email == 'n':
  36.             pass
  37.         else:
  38.             new_email = input("Please enter a valid email address: ")
  39.  
  40.     def prof_review(self):
  41.         review = input("Would you like to display or modify your profile? d/m: ")
  42.         if review == 'm':
  43.             modify = int(input("To modify your date of birth, enter 1. To modify your email addresses, enter 2. "))
  44.             if modify == 1:
  45.                 age_calc()
  46.             elif modify == 2:
  47.                 email_gen()
  48.             else:
  49.                 modify = int(input("Please enter 1 or 2: "))
  50.                 # How can I return this back to the beginning of the function without creating an infinite loop?
  51.         elif review == 'd':
  52.             prof_disp = (
  53.                 'Thank you for creating your profile.'
  54.                 'Here is the information you entered:'
  55.                 'Name: {} {}'.format(new_profile.first_name, new_profile.last_name)
  56.                 'DOB: {} Age: {}'.format(new_profile.dob, new_profile.age)
  57.                 'Email: {} {}'.format(new_profile.email_pri, new_profile.email_sec)
  58.                 )
  59.             print(prof_disp)
  60.         else:
  61.             input("Please enter y or n: ")
  62.             # How can I return this back to the beginning of the function without creating an infinite loop?
  63.  
  64. def new_profile():
  65.     begin = input("Do you want to create a new profile? y/n: ")
  66.     if begin.strip() != 'y':
  67.         print("why, I never!")
  68.         #  how do I get this to end the function?
  69.  
  70.     new_name = input("Enter your name (you will not be able to mofidy this once it is entered): ").split()
  71.    
  72.     new_profile = Profile(new_name[0], new_name[1])
  73.  
  74.     new_profile.age_calc()
  75.    
  76.     new_profile.email_gen()
  77.  
  78.     print("Welcome, {} {}. ".format(new_profile.first_name, new_profile.last_name))
  79.  
  80.     new_profile.prof_review()
  81.  
  82. new_profile()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement