Exercise
Parameterized Function
Objective
Develop a Python program where the main function should look like this:
SayHello("John")
SayGoodbye()
You must define the functions SayHello and SayGoodbye, and they will be called from within the main function. As shown in the example, SayHello must accept a string as a parameter.
Example Python Exercise
Show Python Code
# Define the function SayHello that accepts a parameter (name)
def SayHello(name):
# Print a personalized greeting message using the name parameter
print(f"Hello, {name}! Welcome to the program!") # The greeting includes the name passed to SayHello()
# Define the function SayGoodbye
def SayGoodbye():
# Print a goodbye message
print("Goodbye, thank you for using the program!") # The goodbye message is printed when SayGoodbye() is called
# Main function to execute the program
def main():
# Call the SayHello function with "John" as the argument
SayHello("John") # This will output: "Hello, John! Welcome to the program!"
# Call the SayGoodbye function to display the goodbye message
SayGoodbye() # This will output: "Goodbye, thank you for using the program!"
# Call the main function to run the program
main() # This triggers the execution of SayHello and SayGoodbye
Output
Hello, John! Welcome to the program!
Goodbye, thank you for using the program!
Share this Python Exercise