Python method to calculate the average: first create a new python file; then initialize the value of the sum; then loop the input number to calculate the average, and calculate the value of the sum; finally use "sum/quantity" The formula can be used to calculate the average.
The operating environment of this article: Windows 7 system, python3.5 version, Dell G3 computer.
First of all, let’s take a look at the IPO model for calculating the average.
Input: The number to be entered for calculating the average.
Processing: average algorithm
Output: average
After understanding the IPO mode of the program, we open the local python IDE tool and create a new python file, Name it test6.py.
##Open test6.py and encode, the first step , prompting the user to enter how many numbers to average. [Recommended:python video tutorial]
#The second step is to initialize the value of sum. Note that it is a good coding practice to give an initial value when defining a variable. #The third step is to loop through the numbers to be calculated and calculate the sum value. Finally, calculate the average and output it. Use the "sum/quantity" formula to calculate the average. After the encoding is completed, remember to save and then debug and run. Press the F5 key or click "run"->"run model" in the menu bar to run the program.The above is the detailed content of How to find the average in python. For more information, please follow other related articles on the PHP Chinese website!