Electronic mail¶
Save all functions into the same file named emails.py.
Write the function
address1()that takes a first name and a last name (strings), and returns an e-mail address following the pattern:first.last@student.upc.edu. Examples:>>> address1('joan', 'vendrell') 'joan.vendrell@student.upc.edu' >>> address1('joan', 'Vendrell') 'joan.Vendrell@student.upc.edu' >>> address1('Angela', 'Merkel') 'Angela.Merkel@student.upc.edu'
Note
More tests are provided in the
test-emails1.txtfile.Write the function
address2()that takes a first name and a last name (strings), and returns an e-mail address following the pattern seen in the previous exercice but with a maximum of 10 characters allowed for the first name and a maximum of 15 characters for the last name (in both cases the first characters will be selected). Examples:>>> address2('joan', 'vendrell') 'joan.vendrell@student.upc.edu' >>> address2('Joan', 'Vives_de_la_Cortada') 'Joan.Vives_de_la_Cor@student.upc.edu' >>> address2('Francesc_Xavier', 'Vives_de_la_Cortada') 'Francesc_X.Vives_de_la_Cor@student.upc.edu'
Note
More tests are provided in the
test-emails2.txtfile.Write the function
valid_address()that takes an e-mail address (string), and returnsTrueif it is a valid address andFalseotherwise. A string represents a valid address if it contains one and only one ‘@’ symbol and there are at least 2 characters on the left of the ‘@’ symbol. Examples:>>> valid_address("pepet@lsi.upc.edu") True >>> valid_address("pepet.lsi.upc.edu") False >>> valid_address("@pepet.upc.edu") False >>> valid_address("t@pepet.upc.edu") False >>> valid_address("pe@pepet.upc.edu") True >>> valid_address("pepa@pepet@upc.edu") False
Note
More tests are provided in the
test-emails3.txtfile.Write the function
generate_password()that takes a first name, a last name and a dni (3 strings), and returns a password with the first three characters of the first name, then the first three characters of the last name and the two last digits of the dni. Examples:>>> generate_password("Salvador", "Espriu", "99123457N") 'SalEsp57' >>> generate_password("Ramon", "Llull", "99654321J") 'RamLlu21'
Note
More tests are provided in the
test-emails4.txtfile.
Solutions
A solution of these functions is provided in the
emails.py file.