Robotics & Artificial Intelligence
Define function.
Python Functions
1 Like
Answer
A function is a program module (a part of the program) used simultaneously at different instances in a program to perform a specific task. In other words, a Python function is a block of reusable code designed to perform a specific task which allows to encapsulate code, making it more modular, readable and easier to debug.
Answered By
1 Like
Related Questions
Write a user-defined function
def HCF()to input two numbers from the user. The program calculates greatest common divisor of the two numbers inside the function. Finally, it returns the value to main program to display the result.Sample Input: First Number: 25
Second Number: 60
HCF = 5
Write a user-defined function
def Fact()to input 1 to 5 from the user. The program calculates the factorial of each number inside the function. Finally, it returns the values to main program to display the result.Hint:
def Fact(n): f = 1 for a in range(1, n+1): f = f * a return f # main program for i in range(1, 6): print("Factorial of", i, "=", Fact(i))What are the components of a function?
How will you define a function?