Home > Article > Backend Development > How to sum in python
The method of summing in python: first define an array and input the integers to be summed; then use a for loop to save it in the array; then call the sum function to calculate the sum of all integers; finally output the calculated result The sum of all integers.
The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.
Method of summing in python:
1. First, define an array to save all the integers that are summed.
#2. Enter the number of integers to be summed and save it in the variable n.
#3. Use a for loop to control the input of all summed integers.
#4. Enter all the summed integers and save them in the array.
5. Output all the summed integers, as shown in the figure below.
#6. Call the sum function to calculate the sum of all integers.
#7. Finally, output the calculated sum of all integers.
#8. Run the program and input the summed integers according to the number of integers entered, and the computer will calculate the sum of their integers.
Related free learning recommendations: python video tutorial
The above is the detailed content of How to sum in python. For more information, please follow other related articles on the PHP Chinese website!