Write The Definition of a Function Named Twice That Receives an Integer Argument And Returns an Integer That is Twice The Value of The Parameter

Hi in this article you will learn about writing a Python function named as twice to multiply a number by 2 and return the result.

Let's try to solve this using the Python program.

 

Write The Definition of a Function Named Twice That Receives an Integer Argument And Returns an Integer That is Twice The Value of The Parameter

 

 


Write The Definition of a Function Named Twice That Receives an Integer Argument And Returns an Integer That is Twice The Value of The Parameter

define a function named as twice by  passing the input argument as an integer variable named as number to it.  using the return statement multiply the number by 2 and return it,  as  shown below

def twice(number):
    return number * 2




In the main program take a new  integer variable n and ask a user to enter a number using the input function call and then convert it into an integer.  then take another variable named as result and call the function by  passing the user entered number.

Once the function gets executed, use the print statement to print the  return value of the function.

n = int(input("Enter a Number : "))
result = twice(n)
print("Twice The Value of The Parameter is : ", result)




Python program
==================


def twice(number):
    return number * 2

n = int(input("Enter a Number : "))
result = twice(n)
print("Twice The Value of The Parameter is : ", result)





Output
=================
Enter a Number : 90
Twice The Value of The Parameter is :  180




Output
================
Enter a Number : 78
Twice The Value of The Parameter is :  156




Output
=================
Enter a Number : 34
Twice The Value of The Parameter is :  68





Conclusion
=====================
The above program is a simple example and how you define a function and process the integer variables,  execute  the above Python program by providing the random integer value as an input to it.

Comment it  down below if you have any query related to the above Python program.




Post a Comment

0 Comments