197k views
2 votes
Write a program that loops one thousand times. add all the even numbers and display the results. add all the odd numbers and display the results.

1 Answer

5 votes
# Python v3

odd = 0
even = 0

for i in range( 1000 ): # Note: zero indexed!
if( i % 2 ):
even += i
else:
odd += i

print( "The even numbers add up to %d" % even )
print( "The odd numbers add up to %d" % odd )
User MaddEye
by
6.7k points