Python Function:
A function in Python is a reusable block of code that performs a specific task.
It starts with the def keyword, followed by the function name and parentheses.
Functions can accept inputs (parameters) and return outputs, helping to organize and simplify code.
Function Syntax in Python:
def function_name(parameters):
# Code to perform a task
return output
Basic Example:
Simple example of a function that adds two numbers:
Program :
Output :
Question 1 :
Create a function called add(), sub(), mul(), div() in Python. Each function should take user inputs for a and b, perform the respective arithmetic operation, and print the result.
Program:
Question 2:
Write a Python function that calculates the area of a rectangle. The program should ask the user to enter the length and width of the rectangle and then display the result.
Program :
0 Comments