开始使用免费开始使用

自定义函数语法

作为 IT 支持团队的一员,您经常需要把员工姓名转换为公司邮箱地址。公司采用统一格式:名(小写)+ 点 + 姓(小写)+ @techcompany.com。例如,"Jane Doe" 会变成 [email protected]

为了避免反复手动创建邮箱,您将编写一个自定义函数来自动完成这个任务。

本练习是课程的一部分

Python 中级:面向开发者

查看课程

练习说明

  • 定义一个名为 generate_email 的函数,接收一个名为 full_name 的参数。
  • 在函数中返回生成的 email
  • 使用字符串 full_name 调用该函数。

交互式实操练习

通过完成这段示例代码来试试这个练习。

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(____(____))
编辑并运行代码