I have to convert a piece of C++ code to Python. Except I can't understand what it's doing. This is the code:
#include <iostream>
using namespace std;
int calculate(int values[], int size) {
int answer = 0;
for (int 1 =0; i< size; i +=1)
}
answer += values[1];
}
return answer;
}
int main() {
int myArray[5] = {0, 2, 4, 8, 16};
count << "The answer is " << calculate(myArray, 5);
}
This is my attempt at converting it to Python:
def main():
myArray[5] = (0, 2, 4, 8, 16)
print "The answer is ", calculate(myArray, 5)
def intCalculate(intValues, intSize):
intAnswer = 0
i = 0
if i < intSize:
for i in intAnswer:
intAnswer += values[i]
return intAnswer
main()
Thank you