I am trying to get the sum of several numbers in python. I will input one number for the first in order to determine the numbers to take. Then, I will add all numbers according to the number I put before.
Here are the sample input and output.
input
4
1 5 7 9
output
22
I always used c++ to practice programming, so this problem is really tricky for me. If I solve this question in c++, I can make a program for this task easily like the code below.
#include <iostream>
using namespace std;
int main()
{
int numbers;
int num;
int total = 0;
cin >> numbers;
for (int i = 0; i < numbers; i++)
{
cin >> num;
total = total + num;
}
cout << total;
return 0;
}
However, the way c++ and python take the input is different, I strove to find out the solution, but I couldn't. Can you help me with solving this task? I really appreciate for your help.