Presentation is loading. Please wait.

Presentation is loading. Please wait.

Suppose I want to add all the even integers from 1 to 100 (inclusive)

Similar presentations


Presentation on theme: "Suppose I want to add all the even integers from 1 to 100 (inclusive)"— Presentation transcript:

1 Suppose I want to add all the even integers from 1 to 100 (inclusive)
Suppose I want to add all the even integers from 1 to 100 (inclusive). Which of the following code samples will do it? sum = 0 for i in range(2,99,2): sum = sum + i print sum sum = 0 for i in range(2,100,2): sum = sum + i print sum sum = 0 for i in range(2,101,2): sum = sum + i print sum

2 What is the output? Enter the number.
Here’s some code: sum = 0 for i in range(3): for j in range(5): sum = sum + 1 print sum

3 What is the output? Enter the number.
Here’s some code: sum = 0 for i in range(3): for j in range(5): sum = sum + j print sum


Download ppt "Suppose I want to add all the even integers from 1 to 100 (inclusive)"

Similar presentations


Ads by Google