# Python Program to find Average of N Numbers

Last Updated:

## Using for loop

In the following example, we will find the average of numbers between 1 and 10 using for loop.

### Example

Python Compiler
import math start = 1; end = 10; total = 0; count = end - start + 1 print("Average of numbers between %d and %d:\n" % (start, end)) for start in range(start, end+1): total += start print("Total = %d" % total) print("Count = %d" % count) print("Average is %.2f" % float(total/count))

## Using while loop

In the following example, we will find the average of numbers between 1 and 10 using while loop.

### Example

Python Compiler
import math start = 1; end = 10; total = 0; count = end - start + 1 print("Average of numbers between %d and %d:\n" % (start, end)) while(start <= end): total += start; start += 1; print("Total = %d" % total) print("Count = %d" % count) print("Average is %.2f" % float(total/count))

## Find Average of N Numbers for any Given Range

In the following example, we will find the average of N numbers between the user given range.

### Example

Python Compiler
import math start = int(input("Enter a (int) starting number: ")); end = int(input("Enter a (int) ending number: ")); total = 0; count = end - start + 1 print("Average of numbers between %d and %d:\n" % (start, end)) while(start <= end): total += start; start += 1; print("Total = %d" % total) print("Count = %d" % count) print("Average is %.2f" % float(total/count))