0
0
Pythonprogramming~15 mins

Function definition and syntax in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Function definition and syntax
๐Ÿ“– Scenario: You are learning how to create your own functions in Python. Functions help you group instructions together so you can reuse them easily, like a recipe you follow whenever you want to bake a cake.
๐ŸŽฏ Goal: Build a simple function called greet that prints a welcome message when called.
๐Ÿ“‹ What You'll Learn
Create a function named greet with no parameters
Inside the function, print the exact message: "Hello, welcome!"
Call the function greet to show the message
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Functions help programmers organize code into reusable blocks, making programs easier to read and maintain.
๐Ÿ’ผ Career
Knowing how to define and use functions is a basic skill required for almost all programming jobs.
Progress0 / 4 steps
1
Create a function named greet
Write a function definition for a function called greet with no parameters. Inside the function, write a print statement that prints exactly "Hello, welcome!".
Python
Need a hint?

Use the def keyword to start a function. Remember to indent the print line inside the function.

2
Call the function greet
Add a line of code that calls the function greet to run the code inside it.
Python
Need a hint?

To call a function, write its name followed by parentheses.

3
Add a variable inside the function
Inside the greet function, create a variable called message and set it to the string "Hello, welcome!". Then change the print statement to print the message variable instead of the string directly.
Python
Need a hint?

Assign the string to message and then print message.

4
Run the program to see the output
Run the program and print the output. The output should be exactly Hello, welcome!.
Python
Need a hint?

Make sure you called the function greet() so it prints the message.