Home  >  Article  >  Backend Development  >  How to find the average in python

How to find the average in python

藏色散人
藏色散人Original
2021-03-01 14:23:3077558browse

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.

How to find the average in python

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.

How to find the average in python

How to find the average in python

How to find the average in python

##Open test6.py and encode, the first step , prompting the user to enter how many numbers to average. [Recommended:

python video tutorial]

How to find the average in python

#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.

How to find the average in python

#The third step is to loop through the numbers to be calculated and calculate the sum value.

How to find the average in python

Finally, calculate the average and output it. Use the "sum/quantity" formula to calculate the average.

How to find the average in python

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.

How to find the average in python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn