Python Armstrong NumberPython Average of N NumbersPython Biggest of Three NumbersPython Common DivisorsPython Composite NumberPython Condense a NumberPython Even NumberPython Factorial of a NumberPython Fibonacci SeriesPython GCDPython LCMPython Leap YearPython Multiplication TablePython Number CombinationPython Odd NumberPython Palindrome NumberPython Perfect NumberPython Prime FactorPython Prime NumberPython Sum of DigitsPython Swapping Two Numbers

Python Array ProgramsPython Converter ProgramsPython Star Patterns ProgramPython Number Patterns ProgramPython Alphabet Patterns ProgramLast Updated:

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

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))

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

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))

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

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))