Question: 2. (3096) Write a Python program that calculates the sum of 1 + 2 + 3 + .. + 100 (which is 5050) but breaks

2. (3096) Write a Python program that calculates the sum of 1 + 2 + 3 + .. + 100 (which is 5050) but breaks out of the loop right away when the sum is bigger than 2000 It should print "At iteration k, the sum of 1+2+.. +kis sss> 2000", where k and sss are calculated in your for loop and printed out. It is clear that k > 80 since 1+2 +-+ 80-3240 (by math formula or by C# for loop). Your program should find the exact value of k when the sum is > 2000 the first time. To clarify: suppose I am asking you instead to break out of the loop when the sum is bigger than 12, you have 1+2+3+4-10 and 1+2+3+4+5-15, so your program will print At iteration 5, the sum of 1+2+... +5 is 15> 12". Your program should break out after iteration
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
