Functions With Ingredients ๐
Your cheer() did the exact same thing every time. Kind of boring, right?
Put a name inside the parentheses when you define a function and it becomes a parameter โ a blank space you fill in when you call it:
def greet(name):
print(f"Hey {name}! Welcome back ๐")
greet("Zoe") # โ Hey Zoe! Welcome back ๐
greet("Milo") # โ Hey Milo! Welcome back ๐
One function, endless different greetings. Whatever you put inside the
parentheses when you call it becomes name inside the function.
The parameter only exists inside the function โ it's the function's own private variable.
Your mission
- Build a function
greetthat takes one parameter:def greet(name): - Inside, print a greeting that includes
name(use an f-string) - Call it with 3 different names so you get 3 different greetings
Your code
Press โถ Run to see what your code does!