write a program to display Average of numbers from N to M in python?
Python program that calculates the average of all numbers from N to M:
The program prompts the user to input two integer values, N and M, representing the start and end points of the range of numbers we want to average.
Next, the program initializes two variables, sum and count, to zero. The sum variable will be used to keep track of the sum of all numbers in the range, while the count variable will keep track of the total number of numbers in the range.
The program then uses a for loop to iterate over each number in the range from N to M (inclusive). For each number, the program adds it to the sum and increments the count by 1.
After the loop, the program checks if the count variable is zero. If it is, the program displays an error message to the user, indicating that the input is invalid since we cannot divide by zero. Otherwise, the program calculates the average by dividing the sum by the count, and displays the result to the user.
The program thus outputs the average of all the numbers in the range from N to M.