1 of 4
Your Python Bot is connected to a real Discord server! Write functions, run your code, then click Send to Discord to see your bot post messages live.
Write two functions that generate greeting and farewell messages for users joining and leaving a server.
greet(name)Welcome to the server, Alex! Glad to have you here.farewell(name, days_active)days_active is more than 30, include "You were a legendary member!""Hope to see you again soon!"def greet(name): # Return a welcome message using an f-string pass def farewell(name, days_active): # Return a goodbye message # Use a conditional to check days_active pass # Test your functions: print(greet("Alex")) # Output: Welcome to the server, Alex! Glad to have you here. print(greet("Jordan")) # Output: Welcome to the server, Jordan! Glad to have you here. print(farewell("Sam", 45)) # Output: Goodbye Sam! You were a legendary member! print(farewell("Riley", 10)) # Output: Goodbye Riley! Hope to see you again soon!
Welcome to the server, Alex! Glad to have you here.
Welcome to the server, Jordan! Glad to have you here.
Goodbye Sam! You were a legendary member!
Goodbye Riley! Hope to see you again soon!
For greet, you just need to return an f-string:
return f"Welcome to the server, {name}! ..."
For farewell, use an if/else to pick the right message:
if days_active > 30: return f"Goodbye {name}! You were a legendary member!" else: return f"Goodbye {name}! Hope to see you again soon!"
def greet(name): return f"Welcome to the server, {name}! Glad to have you here." def farewell(name, days_active): if days_active > 30: return f"Goodbye {name}! You were a legendary member!" else: return f"Goodbye {name}! Hope to see you again soon!"
print() displays themWrite your code below. Click Run to test locally, then click Send to Discord to have the bot post your output to the server!