I have a code which is was written in C++.
I want to convert this to Python 3, but there is some problem that starts from for(;;)
loop to res+=arr[i]
.
There is my C++ pattern:
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
vector<int> arr;
for(;;){
cin>>n;
if(n==0) break;
else arr.push_back(n);
}
int res = 0;
for(int i=0;i<arr.size();i++){
res+=arr[i];
}
cout<<res<<" "<<arr.size();
return 0;
}
And I want to convert to Python 3.
from itertools import count
arr = []
for i in count(0):
n = int(input())
if(n==0): break
else: arr.append(n)
res = 0
for i in arr:
res+=arr[i]
print(res+" "+len(arr))
So there are several mistakes that are hidden from me because I am coding in C++.