Aan de slagGa gratis aan de slag

Custom function syntax

As part of the IT support team, you frequently need to convert employee names into their company email addresses. The company follows a standard email format: first name (lowercase) + dot + last name (lowercase) + @techcompany.com. For example, "Jane Doe" becomes [email protected].

Instead of manually creating these emails repeatedly, you'll build a custom function to automate this task.

Deze oefening maakt deel uit van de cursus

Intermediate Python for Developers

Cursus bekijken

Oefeninstructies

  • Define a function called generate_email that takes one argument called full_name.
  • Return the generated email from the function.
  • Call the function on the full_name string.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

full_name = "Alan Turing"

# Define the generate_email function
____ ____(full_name):
    name_parts = full_name.split()
    email = name_parts[0].lower() + '.' + name_parts[1].lower() + '@techcompany.com'
    
    # Return the email address
    ____ ____

# Call the function on the full_name string
print(____(____))
Code bewerken en uitvoeren