Given a few numbers. Calculate their sum. First enter the number of numbers N. Then exactly N integers are entered.

What is the smallest number of variables needed to solve this problem?

i=int(input()) a=i*int(input()) z=0 for i in range(a,a-1): z+=a print(z) 

    2 answers 2

    Zero. The quantity is immediately used as the upper limit, then the map, which reads the rest, then the sum is output.

    The code with range works, but in addition to the sum displays the elements of range.
    http://ideone.com/3uuq1X

     print(sum(map(int, map(input, range(int(input())))))) 

    But instead of range you can use a list of the required number of empty lines.
    http://ideone.com/kJ4A6W

     print(sum(map(int, map(input, [''] * int(input()))))) 
    • tin, well, why scare a person right away =) besides, most likely his teacher will not appreciate this answer, or even worse - he will not understand = ( - rdorn
    • @rdorn, "What is the smallest number of variables needed to solve this problem?" - probably, any other quantity will not be the smallest? - Qwertiy
    • understand everything thanks. - sigmon123
    • @ sigmon123, in this case, you must accept the answer. - Qwertiy
    • Answer is accepted ✓ Check - sigmon123
     s = 0 for i in range(int(input())): s += int(input()) print(s) 

    I decided 3 hours, the answer was on the git hub, cake

    • Although the link can find the answer to the question, it is better to point out the most important thing here, and give the link as a source. If the page to which the link leads will be changed, the response link may become invalid. - From the queue of checks - Streletz
    • @Streletz, the code in the answer is the answer. What is the link you prevented? - Qwertiy