Created
          October 18, 2020 06:02 
        
      - 
      
 - 
        
Save sharkdeng/d4c94597fda16962db8ec76341ef3bf1 to your computer and use it in GitHub Desktop.  
    SLK-581 code
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def slk581(name, birthdate, gender): | |
| result = '' | |
| first_name, last_name = name.split(' ') | |
| # Take the 2nd, 3rd, and 5th letters of a record's family name (surname) | |
| if len(last_name) >=5 : | |
| result += last_name[1] + last_name[2] + last_name[4] | |
| elif len(last_name) >= 3: | |
| result = last_name[1] + last_name[2] + '2' | |
| else: | |
| result = last_name[1] + '22' | |
| # Take the 2nd and 3rd letters of the record's given name (first name) | |
| result += first_name[1] + first_name[2] | |
| # Take the day, month and year of the person, concatenated in that order (ddmmyyyy) to form the date of birth | |
| if len(birthdate) == 8: | |
| result += birthdate | |
| # Take the gender of the person (1=male, 2=female, 9=unknown) | |
| if gender == 'male': | |
| result += str(1) | |
| elif gender == 'female': | |
| result += str(2) | |
| else: | |
| result += str(9) | |
| # 5) If names too short use 2, if full name component missing use 999 | |
| return result | |
| def test(): | |
| assert(slk581('Brian Schmidt', '24021967', 'male')) == 'chiri240219671' | |
| assert(slk581('Elizabeth II', '21041926', 'female')) == 'I22li210419262' | |
| assert slk581('Limin Deng', '11081992', 'female') == 'en2im110819922' | |
| test() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment