Answer to Question #225392 in Python for Dion Martins

Question #225392

The sum of the first n positive integers can be computed by the formula

sum(1..n) = 1 + 2 + 3 + 4 + · · · + n = n(n + 1)/2

Write a short Python program that computes the sum of the first 100 positive integers and prints it to the screen, using format specifiers when printing instead of converting each item to a string. Use variables to represent the 1, the 100, and the result of the computation. Your program must compute the 5050 value. You cannot just print the result to the screen. You must compute it first from the 100. The goal is for the output to look exactly the same.The output is as shown below:

sum(1..100) = 5050


1
Expert's answer
2021-08-11T15:00:28-0400
m = 1
n = 100
r = n*(n+1)//2
print('sum({:d}..{:d}) = {:d}'.format(m, n, r))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS