Download presentation
Presentation is loading. Please wait.
Published byBarrie Lawson Modified over 5 years ago
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.