Table of Contents
show
The following are the prototypes of function,
Function without arguments and without return type
In this type, no argument is passed through the function call and no output is returned to main function. The sub function will read the input values perform the operation and print the result in the same block
Program: Exponentiation of a number
def Myexp():
x = int(input('Enter the first number'))
y = int(input('Enter the exponent'))
z = x ** y
print("Exponent of two numbers ",z)
Myexp()
Output
Enter the first number3
Enter the exponent2
('Exponent of two numbers ', 9)
Function with arguments and without return type
Arguments are passed through the function call but output is not returned to the main function
Program: To find square of a number
def Mysquare(a):
c = a * a
print ("Square of ",a,"is",c)
x = int(input("Enter the number to find square"))
Mysquare(x)
Output
Enter the number to find square4
('Square of ', 4, 'is', 16)
Function without arguments and with return type
In this type no argument is passed through the function call but output is returned to the main function
Program: Exponentiation of a number
def Myexp():
x = int(input('Enter the first number'))
y = int(input('Enter the exponent'))
z = x ** y
return z
c = Myexp()
print("Result = ",c)
Output
Enter the first number3
Enter the exponent4
('Result = ', 81)
Function with arguments and with return type
In this type arguments are passed through the function call and output is returned
Program: To find square of a number
def Mysquare(a):
c = a * a
return c
x = int(input("Enter the number to find square"))
c=Mysquare(x)
print ("Square of ",x,"is",c)
Output
Enter the number to find square 4
('Square of ', 4, 'is', 16)
Views: 0