Series Summation using for loop in python
问题 Let's assume this series 1+2+3+....+n in c with for loop we can easily done this for(i=1;i<=n;i++) { sum += i; } in python i am able to done this using while loop while(num <= n): sum += num num = num+1 but i can't do it using python for loop 回答1: Python syntax is a bit different than c. In particular, we usually use the range function to create the values for the iterator variable (this is what was in Stephen Rauch's comment). The first argument to range is the starting value, the second is