Home>Article>Backend Development> How to use sum function in python to sum

How to use sum function in python to sum

王林
王林 Original
2020-05-09 10:17:30 12850browse

How to use sum function in python to sum

First, define an array to save all the integers that are summed.

How to use sum function in python to sum

#Enter the number of integers to be summed and save it in the variable n.

How to use sum function in python to sum

Use a for loop to control the input of all summed integers.

How to use sum function in python to sum

Enter all the summed integers and save them in the array.

How to use sum function in python to sum

Output all the summed integers, as shown in the figure below.

How to use sum function in python to sum

Call the sum function to calculate the sum of all integers.

How to use sum function in python to sum

Finally, output the calculated sum of all integers.

How to use sum function in python to sum

The output results are as follows:

How to use sum function in python to sum

Recommended tutorial:python tutorial

The above is the detailed content of How to use sum function in python to sum. 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