reich9338 reich9338
  • 26-10-2017
  • Computers and Technology
contestada

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.

Respuesta :

rsmith6559
rsmith6559 rsmith6559
  • 27-10-2017
# 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 )
Answer Link

Otras preguntas

Mackenzie lives in Morristown, where the cost of living increases by 3% every year. If Mackenzie spends $22,880 this year, how much can she expect to spend 3 ye
MATH 100 POINTS!!QUESTION, THE ANSWER IS ''IMPOSSIBLE'' HOWEVER PROVIDE THE PROOF WITH AN EXPLANATION FOR WHY IT IS IMPOSSIBLE. thank you.
How many moles are in 58.90 liters of methane (CH4)?
Add the expression -2.4n-3 and -7.8n 2
What should be the overall length of a typical cover letter O A. OB. O C. O D. one paragraph two pages five pages less than a page
Add the expression -2.4n-3 and -7.8n 2
The genotype of an organism and the interaction of the genotype with the environment determine the organism's ________ or observable characteristics
Why is the use of an international system of measurement important for science?
The figure below is a net for a triangular pyramid. 8.66 m 10 m If all the triangles are equilateral, what is the surface area of the pyramid, in square meters?
TRUE or FALSE In the First Continental Congress, many members still wanted to find a peaceful solution to the problems with England.