Skip to content
Home » Average of Two Numbers in Python using Function

Average of Two Numbers in Python using Function

Learn about Average of Two Numbers in Python using Function in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

Average of Two Numbers in Python using Function

# Program to find average of two numbers using function

#function
def avg_num(num1, num2): 
    avg = (num1 + num2) / 2
    return avg  

# take inputs
num1 = float(input('Enter first number: '))
num2 = float(input('Enter second number: '))

# calling function
average = avg_num(num1, num2)

#print result
print('The average of numbers = %0.2f' %average)

Output:

Enter first number: 6
Enter second number: 8
The average of numbers = 7.00

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Python Average of Two Numbers