
Charles M. answered 10/09/19
All-But-Dissertation in Computer Science
I presume this is python.

Bent R.
asked 10/07/19Charles M. answered 10/09/19
All-But-Dissertation in Computer Science
I presume this is python.
Suzanne O. answered 10/09/19
International Experience and Multiple State Certifications
You did not specify the language you are using. This could change the answer a little or a lot.
Try:
a = 1
sum = 0
x = range(1, 51, 2)
for a in x:
sum+=a
print('The sum of the odd integers from 1 to 51 is ', sum)
That example is in python which has a built in range type.
Java does not have this type built in, so a for loop with i=1 and i<=51 , sum+=i, incremented with i+=2 would work.
Older languages (BASIC, Pascal, C, C++, ...) would look closer to the Java example.
Hope this helps.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Charles M.
A more Pythonic version would be sum([i for i in range(1,52) if i%2 != 0])10/09/19