Programming with Python

⌘K
  1. Home
  2. Docs
  3. Programming with Python
  4. Variables, Expression and...
  5. Function
  6. Function Prototypes

Function Prototypes

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)

Loading

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments