Making a Function in Python that converts centimeters into inches
The tasks that are to be performed multiple times in Python programming can become very tedious. Fort this reason 'functions' are employed.
We simply put some repetitive task into a function and after that, we have just to recall the defined function and the result will be thrown at us in an instant. That is the beauty of python functions.
Below we have defined a function for converting centimeters into inches. Now we don't need to write the formula again and again in our code to convert centimeters into inches. We just have to call the function and put our value in centimeters and the same function will convert it into inches. That's all!
Syntax of Functions:
def ----------> define
inches--------> function name
()--------------> parameter that takes an argument
return ---------> keyword in python that returns the result
formula---------> the body of function
Centimeters into Inches Function Definition
Now, you can just enter the value in the called function and it will return the result in inches. In the above example, 7 centimeters is being converted into inches and printed on the terminal.
That's it for now!
Comments
Post a Comment
Write something to CodeWithAbdur!