Learn about Find the Average of 4 Numbers using Function in Python in the below code example. Also, refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Find the Average of 4 Numbers using Function in Python
# Program to find average of four numbers using function
#user-defined function
def avg_num(num1, num2, num3, num4,):
avg = (num1 + num2 + num3+ num4) / 4
return avg
num1 = float(input('first number: '))
num2 = float(input('second number: '))
num3 = float(input('third number: '))
num4 = float(input('four number: '))
# function call
average = avg_num(num1, num2, num3, num4)
# print result
print('The average of numbers = ',average)
Output:
first number: 4 second number: 6 third number: 8 four number: 10 The average of numbers = 7.0
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Average of 4 Numbers in Python