We will use a list to save numbers and will find the average of given numbers in the list. We know that to find the average of numbers, we simply divide the sum of all numbers by the count of all numbers. For example, to find the average of 2, 3, 4, and 5, we will simply add them(2+3+4+5 = 14) and simply divide them with 4(14÷4 = 3.5). Now let’s convert the whole process to find the average of the given numbers with Python Code.
1. Python Code to find the average of given numbers using built-in methods
numbers = [1, 2, 3, 4]
total = sum(numbers)
average = total/len(numbers)
print(average)
Output:
2.5
2. Python Code to find the average of given numbers using for loop
numbers = [1, 2, 3, 4]
total = 0
count=0
for i in numbers:
total = total + i
count = count + 1
average = total/count
print(average)
Output:
2.5
Also Read:
- Calculate Mean, Median, and Mode Python
- Assignment|How to check prime number in python?
- Assignment Helper|How to find the factorial of a number in python?
- Assignment Helper|Python Program to Check if a Number is Positive, Negative, or 0
- Assignment Helper | Python Program to Find the Square Root
- Assignment Helper | Python Program to Display the multiplication Table
- Assignment Helper | Python Program to Find the Largest Among Three Numbers
- Assignment Helper | Leap Year Program in Python
- Assignment Helper | Add Two Numbers Python
- Assignment Helper | Python Program to Calculate the Area of a Triangle
- Assignment Helper | Python Program to Solve Quadratic Equation
- Assignment Helper | Python Program to Swap Two Variables
- Assignment Helper | Python Program to Generate a Random Number
- Assignment Helper | Python Program to Convert Kilometers to Miles
- Assignment Helper | Python Program to Convert Celsius To Fahrenheit
- Assignment Helper | Python Program to Check if a Number is Odd or Even
- Assignment Helper | Python Program to Print all Prime Numbers in an Interval
- Python Program to Print the Fibonacci sequence
- Assignment Helper | Python Program to Check Armstrong Number
- Assignment Helper | Python Program to Convert Kilometers to Miles
- Assignment Helper | Python Program to Find Armstrong Number in an Interval
- Assignment Helper | Python Program to Find the Sum of Natural Numbers
- Assignment Helper | Python Program to Display Powers of 2 Using Anonymous Function
- Assignment Helper | Python Program to Find Numbers Divisible by Another Number
- Assignment Helper | Python Program to Convert Decimal to Binary, Octal, and Hexadecimal
- Assignment Helper | Python Program to Find ASCII Value of Character
- Assignment Helper | Python Program to Find HCF or GCD
- Factorial Programming in Python
- GCD Recursion in Python
- What are Generators, Generator Functions, Generator Objects, and Yield?